This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

XSLT doubt

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a basic XSLT example below. First I will show you the xml, then the xsl sheet, and then the ouput.
All these works fine.
But when I try to use a variable name, is not working.

XML>
<page>
<group>ColumnB</group>
<rows>
<row>
<ColumnA>any value</ColumnA>
<ColumnB>id1</ColumnB>
<ColumnC>any vlaue</ColumnC>
</row>
<row>
<ColumnA>any value</ColumnA>
<ColumnB>id2</ColumnB>
<ColumnC>any value</ColumnC>
</row>
<row>
<ColumnA>any value</ColumnA>
<ColumnB>id1</ColumnB>
<ColumnC>any value</ColumnC>
</row>
</rows>
</page>

XSL>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
<xsl:template match="/page">
<!-- Any stuff -->

<!-- BODY -->
<xsl:call-template name="template2">
<xsl:with-param name="data" select="rows/row" />
</xsl:call-template>

<!-- Any stuff -->
</xsl:template>

<xsl:template name="template2">
<xsl aram name="data" />

<xsl:variable name="filter-column" select="group"/>
<xsl:variable name="filter-identifier" select="$data[1]/*[name() = $filter-column]"/>
<xsl:variable name="filtered-data" select="$data[ColumnB = $filter-identifier]"/>

<xsl:text> </xsl:text>
<xsl:value-of select="$filter-column"/>
<xsl:text> </xsl:text>
<xsl:value-of select="$filter-identifier"/>
<xsl:text> </xsl:text>
<xsl:value-of select="count($filtered-data)"/>
</xsl:template>
</xsl:stylesheet>

OUTPUT:
ColumnB
id1
2

This is all fine, but where I try to use a variable. Instead of:
<xsl:variable name="filtered-data" select="$data[ColumnB = $filter-identifier]"/>

Use this(changing just ColumnB literal to its variable, that is the same content):
<xsl:variable name="filtered-data" select="$data[$filter-column = $filter-identifier]"/>

Does not work, because it comes up with this:
ColumnB
id1
0

Where the last number, should be 2.

Can any body help me with this?
Thanks!
 
What are you saying? I thought you said that Santa gave you that. And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic