0

I am using the node-set built-in-function to convert an xsl variable into a nodeset as in the code below

<xsl:variable name="allotmentValuesNodeSet" select="msxsl:node-set($allotmentValues)"/>

The command <xsl:copy-of select="$allotmentValuesNodeSet"/> produces the following output:

<values>  
        <month>Mar</month>
        <incomeQTD>1499.63109246680</incomeQTD>
        <realizedQTD />
        <incomeYTD>1519.35773710483</incomeYTD>
        <realizedYTD />
        <incomePrevYTD>1519.35773710483</incomePrevYTD>
        <realizedPrevYTD />

        <month />
        <incomeQTD />
        <realizedQTD />
        <incomeYTD />
        <realizedYTD />
        <incomePrevYTD />
        <realizedPrevYTD />

 </values>

When I try to query the node-set variable with this xsl command <xsl:value-of select="count($allotmentValuesNodeSet/values/month)"/> I always get 0, although the result should be 2.

The allotmentValues variable is included between other, outer xml nodes. If I do not include it between any xml nodes, then the code works as expected.

Is there any obvious casue (e.g. namespace related maybe?) for why querying xsl node-sets might break?

If needed, I will try to come up with a simple example to illustrate my problem (I cannot exactly post the code snippet of the issue since it's proprietary code).

teodron
  • 1,410
  • 1
  • 20
  • 41

2 Answers2

1

Fix the variable creation with e.g. <xsl:variable name="allotmentValues" xmlns="">...</xsl:variable> and probably the unprefixed path <xsl:value-of select="count($allotmentValuesNodeSet/values/month)"/> works.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
0

I have found the solution from this question to work in my situation.

Brief description of the issue and solution:

  • if the <xsl:variable/> from which we derive the node set is included in an xml block with a default namespace, it inherits that namespace
  • hence, to correctly carry out XPath queries, one can prefix the nodes with the name of the default namespace, e.g. count($allotmentValuesNodeSet/inheritedNS:values/inheritedNSmonth) instead of count($allotmentValuesNodeSet/values/month)
Community
  • 1
  • 1
teodron
  • 1,410
  • 1
  • 20
  • 41