mu shaikh
mu shaikh

Reputation: 99

XSLT 2.0 for loop one XML node which matches with data in other XML

I'm trying to loop through below XML B on Root node which matches with XML A with the XSLT pseudo code as given below. As i'm new to XSLT please help

XML A:

<P_OUT_PARTNUMBERS>
        <Row>
            <Column>53</Column>
        </Row>
        <Row>
            <Column>54</Column>
        </Row>
</P_OUT_PARTNUMBERS>

XML B:

<P_OUT_PARTNUMBERS>
        <Root>
            <Field>53</Field>
        </Root>
        <Root>
            <Field>30</Field>
        </Root>
</P_OUT_PARTNUMBERS>

XSLT:

<xsl:for-each select="$XMLB/Root">
    <xsl:variable name="Fieldvalue" select ="/Field"/>
    <xsl:if test="$XMLA/Row[Column = $Fieldvalue]/Column" >
          <xsl:value-of select="position()"/>
    </xsl:if>
</xsl:for-each>

I want something like below as i don't want to loose value of position() because of if condition. i.e. position() value should be 1,2,3,..etc with my logic i'm getting 1,3,6,8,..etc not continuos

Upvotes: 0

Views: 252

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167781

If the position() function doesn't do the job you expect or want it to do we will have a hard time to understand what you want to achieve if your explanation relies on asking position() something it doesn't do. What is the task in terms of input/output mapping?

If you want to process P_OUT_PARTNUMBERS/Root[key('col', Field, $docA)] then perhaps just do that with a key e.g. <xsl:key name="col" match="P_OUT_PARTNUMBERS/Row" use="Column"/>. In general moving conditions from nested xsl:ifs to a simple predicate might be more along the lines of having a continuous sequence.

Upvotes: 1

Related Questions