[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Accessing elements with key via string in variable
Hello,
(The problem exists with the key on line 14) I am trying to access 'thing' elements by the value of their 'a' element children. I do not know what the contents of the 'a' elements will be, so I gather the unique values and iterate through them. When I iterate through, I can print the value, placing the value into the key does not return the 'things' that have 'a' children with that value. Additionally, placing a literal string will access the desired nodes, but a variable with the same string content does not. The input, current output, desired output, xslt (with line numbers) and xslt are listed below. Many thanks, Tim ======= Input ======== <things> <thing> <name>thing_1</name> <a>one</a> </thing> <thing> <name>thing_3</name> <a>one</a> <a>two</a> </thing> <thing> <name>thing_4</name> <a>one</a> <a>two</a> <a>three</a> </thing> <thing> <name>thing_5</name> <a>three</a> </thing> </things> ======= Current Output ========= Dynamic Selection (DOES NOT WORK) one 0 two 0 three 0 ======= Desired output ======== Hard-coded selection (DESIRED OUTPUT) one 3 two 2 three 2
======== XSLT w/o line numbers ========= <xsl:transform version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:key name="things-by-a" match="thing" use="a"/> <xsl:template match="/"> <xsl:variable name="as"> <xsl:for-each-group select="//a" group-by="."> <a><xsl:value-of select="current-grouping-key()"/></a> </xsl:for-each-group> </xsl:variable> <xsl:value-of select="concat($NL,'Dynamic Selection (DOES NOT WORK)',$NL)"/> <xsl:for-each select="$as/a"> <xsl:value-of select="concat(.,' ',count(key('things-by-a',.)),$NL)"/> </xsl:for-each> <xsl:value-of select="concat($NL,'Hard-coded selection (DESIRED OUTPUT)',$NL)"/> <xsl:value-of select="concat('one ',count(key('things-by-a','one')),$NL)"/> <xsl:value-of select="concat('two ',count(key('things-by-a','two')),$NL)"/> <xsl:value-of select="concat('three ',count(key('things-by-a','three')),$NL)"/> </xsl:template> <xsl:variable name="NL"> <xsl:text> </xsl:text> </xsl:variable> </xsl:transform>
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|