Note that there are some explanatory texts on larger screens.

plurals
  1. POxslt passing position as a parameter is producing strange results?
    primarykey
    data
    text
    <p>I have an xml file which looks like this:</p> <pre><code>&lt;section&gt; &lt;title&gt; title of section &lt;/title&gt; &lt;table&gt; &lt;title&gt; title of table&lt;/title&gt; &lt;tableData columns = 2&gt; &lt;column width ="50"/&gt; &lt;column width ="100"/&gt; &lt;tableHead&gt; &lt;row&gt; &lt;entry&gt;column 1&lt;/entry&gt; &lt;/row&gt; &lt;row&gt; &lt;entry&gt;column 2&lt;/entry&gt; &lt;/row&gt; &lt;/tableHead&gt; &lt;tableBody&gt; &lt;row&gt; &lt;entry&gt;text&lt;/entry&gt; &lt;entry&gt;abc&lt;/entry&gt; &lt;/row&gt; &lt;row&gt; &lt;entry&gt;text&lt;/entry&gt; &lt;entry&gt;dbe&lt;/entry&gt; &lt;/row&gt; &lt;row&gt; &lt;entry&gt;text&lt;/entry&gt; &lt;entry&gt;fgh&lt;/entry&gt; &lt;/row&gt; &lt;/tableBody&gt; &lt;/table&gt; &lt;/section&gt; </code></pre> <p>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"}</p> <p>My transform looks like this</p> <pre><code> &lt;xsl:template match="//table/tableHead/row/entry"&gt; &lt;xsl:text&gt;{"name": "&lt;/xsl:text&gt;&lt;xsl:value-of select"."/&gt; &lt;xsl:text&gt;", "width":"&lt;/xsl:text&gt; &lt;xsl:call-template name="get_column_width"&gt; &lt;xsl:with-param name ="rowNum"&gt; &lt;xsl:value-of sellect"position()"/&gt; &lt;/xsl:with-param&gt; &lt;/xsl:call-template&gt; &lt;/xsl:template&gt; &lt;xsl:template name ="get_column_width"&gt; &lt;xsl:param-name="rowNum"&gt; &lt;xsl:value-of select="../../../columnWidth[$rowNum]/@width"/&gt; &lt;xsl:text&gt;px"}&lt;/xsl:text&gt; &lt;/xsl:template&gt; </code></pre> <p>Strangely, this produces {"name":"column 1", "width":"50 100px"},{"name":"column 2", "width":"50 100px"}</p> <p>However, when I output only the rowNum parameter I get exactly what I expect:</p> <p>{"name":"column 1", "width":1px"},{"name":"column 2", "width":"2px"}</p> <p>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?</p> <p>Unfortunately changing the xml format is not an option.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload