xslt passing position as a parameter is producing strange results?

unlictgrience

New Member
I have an xml file which looks like this:\[code\]<section> <title> title of section </title> <table> <title> title of table</title> <tableData columns = 2> <column width ="50"/> <column width ="100"/> <tableHead> <row> <entry>column 1</entry> </row> <row> <entry>column 2</entry> </row> </tableHead> <tableBody> <row> <entry>text</entry> <entry>abc</entry> </row> <row> <entry>text</entry> <entry>dbe</entry> </row> <row> <entry>text</entry> <entry>fgh</entry> </row> </tableBody> </table> </section>\[/code\]I need to process each entry in tableHead/row/entry and spit it out in some format that also includes the columnWidth. So, my output must look like {"name":"column 1", "width":"50px"},{"name":"column 2", "width":"100px"}My transform looks like this\[code\] <xsl:template match="//table/tableHead/row/entry"> <xsl:text>{"name": "</xsl:text><xsl:value-of select"."/> <xsl:text>", "width":"</xsl:text> <xsl:call-template name="get_column_width"> <xsl:with-param name ="rowNum"> <xsl:value-of sellect"position()"/> </xsl:with-param> </xsl:call-template> </xsl:template> <xsl:template name ="get_column_width"> <xsl:param-name="rowNum"> <xsl:value-of select="../../../columnWidth[$rowNum]/@width"/> <xsl:text>px"}</xsl:text> </xsl:template>\[/code\]Strangely, this produces {"name":"column 1", "width":"50 100px"},{"name":"column 2", "width":"50 100px"}However, when I output only the rowNum parameter I get exactly what I expect:{"name":"column 1", "width":1px"},{"name":"column 2", "width":"2px"}So, rowNum is 1 and 2 so the select statement will use columnWidth[1] and columnWidth[2], but for whatever reason it just outputs both of them. I tried using columnWidth[1] in the select and it outputs 50 as I would expect. columnWidth[2] outputs 100. I'm really confused here. Using preceding-sibling gave the same result. Is there something wrong with my template matching?Unfortunately changing the xml format is not an option.
 
Back
Top