0
votes

I'm trying to go through a set of nodes thanks to a for-each, and I'd like to select the current node in a variable when the parameters in this node validate few conditions. The problem is that it seems to select the value in the node, and not the actual node itself. And I'd like to be able to use this variable as a nodeset later.

XML ($parameterFile) :

<?xml version="1.0" encoding="UTF-8"?>
    <Cases>
            <Case>
                <Rule LineNumber="10" PartNumber="FT40X40"/>
                <Template>
                    <Drawings>
                        test
                    </Drawings>
                </Template>
            </Case>
            <Case>
                <Rule LineNumber="10" PartNumber="FT40X46k"/>
                <Template>
                    <Drawings>
test2
                    </Drawings>
                </Template>
            </Case>

XSLT :

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="xs"
version="2.0">
<xsl:variable name="GoodCase">
    <xsl:for-each select="$parameterFile/Cases/Case">
        <xsl:choose>
                <xsl:when test="(Rule/@LineNumber = $markerNbLines) and 

(Rule/@PartNumber = $markerPartNumber)">
                    <xsl:value-of select="current()"/>
                </xsl:when>
            </xsl:choose>
        </xsl:for-each>
    </xsl:variable>

    <xsl:for-each select="$parameterFile/$GoodCase/Template/Drawings">
        test
    </xsl:for-each>

Output expected :

test

Thanks !

1
Please edit your question: Include a complete XSLT stylesheet, a well-formed input XML, and your expected output - also in XML or text - not as a description.Mathias Müller
Why is your question tagged XSLT 1.0 while your stylesheet declares version 2.0?michael.hor257k

1 Answers

0
votes

The pb [problem?] is that it seems to select the value in the node, and not the actual node itself.

Well, you are using:

<xsl:value-of select="current()"/>

so that's only expected. You could use <xsl:copy-of>to write the entire node. However, the resulting variable would hold a result-tree-fragment, not a node-set, so if:

And I'd like to be able to use this variable as a nodeset later.

you would be much better off populating your variable in this manner (untested, because no testing is possible with partial code):

<xsl:variable name="GoodCase" select="$parameterFile/Cases/Case[Rule/@LineNumber=$markerNbLines and Rule/@PartNumber=$markerPartNumber]"/>

This stores only a reference to the original nodes and thus is a node-set by itself.