I could not find a question which displays the problem :/ and Im new to xslt, maybe someone can forward me to the right sites.
The task seems simple to me: I would like to declare a variable to use in one node (for filtering out) which comes from checkups in another node. Im used to sql and databases and my approach may be wrong in here. The situation:
<NODES1>
<NODE1 INTV="0" INDEX_ZONE="1" />
<NODE1 INTV="1" INDEX_ZONE="2" />
<NODE1 INTV="1" INDEX_ZONE="2" />
<NODE1 INTV="1" INDEX_ZONE="3" />
<NODE1 INTV="2" INDEX_ZONE="5" />
<NODE1 INTV="2" INDEX_ZONE="6" />
<NODE1 INTV="2" INDEX_ZONE="7" />
<NODE1 INTV="2" INDEX_ZONE="8" />
</NODES1>
</NODES2><
<NODE2 INTV="0" SPTYP="good" />
<NODE2 INTV="1" SPTYP="medium" />
<NODE2 INTV="2" SPTYP="bad" />
</NODES2>
In my stylesheet I want to look at all NODE1 where the data is "bad". The attribute INTV contains a number, which key-pair lies in NODES2.
So based on my SQL thinking I need some kind of:
<xsl:variable name="BAD" select="NODES2/@SPTYP"/> PLUS "WHERE INTV = 2" :D ;D
And put an if in NODES1 like:
<xsl:for-each select="NODES1">
<xsl:choose>
<xsl:when test="@INTV = $BAD">
Anybody got the idea and could help out? I dont even know, if that kind of operation is possible in xslt.
Thanks in advance.
CodePudding user response:
To select by condition, you need to use square brackets in your XPath.
<xsl:variable name="BAD" select="//NODES2/NODE2[@INTV=2]/@SPTYP"/>
This sets the variable to 'bad'
.
I'm not sure what your second part of XSL code is supposed to do since it's missing the statement itself (the when
is basically the if-part of a if/else condition check). In the current state it only checks if an attribute called INTV
is equals to the variable content of $BAD
.
Maybe you can supply a example output, then I will edit my answer for the second part for the question.