• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

XSLT doubt

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Well don't expect me to do the dishes! This ad has been cleaned for your convenience:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic