U
utterberg
Hi, I've got an xml that looks like this:
<section name="Risk">
<label>RISK MANAGEMENT (RM)</label>
<field name="RM.1">
<ref>RM.1</ref>
<label>Text goes here...</label>
<option value="2">Yes</option>
<option value="1">No</option>
<option value="0">-</option>
<data>1</data>
</field>
<field name="RM.2">
<ref>RM.2</ref>
<label>Text 2 goes here...</label>
<option value="2">Yes</option>
<option value="1">No</option>
<option value="0">-</option>
<data>1</data>
</field>
<field name="RM.2">
<ref>RM.2</ref>
<label>Text 2 goes here...</label>
<option value="2">Yes</option>
<option value="1">No</option>
<option value="0">-</option>
<data></data>
</field>
</section>
And what I want to do is loop through all fields and if <data> has
value get the <option>-content it "belongs" to ("Yes", "No" or "-").
So this is my xslt:
<xsl:for-each select="section[@name='Risk']/field">
<xsl:variable
name="data"
select="data" />
<xsl:variable name="optionText">
<xsl:if test="$data!=''">
<xsl:for-each select="option">
<xsl:if test="@value=$data">
<xsl:value-of select="." />
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:variable>
Print:<xsl:value-of select="label" /> <xsl:value-of
select="$optionText" />
</xsl:for-each>
(the thing is this loop is included in a bit more complex context
(wordml) - but for simplicity it is left out)
The problem I'm having with the above xslt is that when <data> has a
value my optionText-variable will run three times and that messes my
structure up. The variable does something strange it gets the value -
in the first example "No". But before and after there's a "gap" sort of
like it has gone through my loop and added some white space.
I don't know if this makes any scense. But I hope so. Maybe there's a
better way to do this?
Thanks in advance!
..christer
<section name="Risk">
<label>RISK MANAGEMENT (RM)</label>
<field name="RM.1">
<ref>RM.1</ref>
<label>Text goes here...</label>
<option value="2">Yes</option>
<option value="1">No</option>
<option value="0">-</option>
<data>1</data>
</field>
<field name="RM.2">
<ref>RM.2</ref>
<label>Text 2 goes here...</label>
<option value="2">Yes</option>
<option value="1">No</option>
<option value="0">-</option>
<data>1</data>
</field>
<field name="RM.2">
<ref>RM.2</ref>
<label>Text 2 goes here...</label>
<option value="2">Yes</option>
<option value="1">No</option>
<option value="0">-</option>
<data></data>
</field>
</section>
And what I want to do is loop through all fields and if <data> has
value get the <option>-content it "belongs" to ("Yes", "No" or "-").
So this is my xslt:
<xsl:for-each select="section[@name='Risk']/field">
<xsl:variable
name="data"
select="data" />
<xsl:variable name="optionText">
<xsl:if test="$data!=''">
<xsl:for-each select="option">
<xsl:if test="@value=$data">
<xsl:value-of select="." />
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:variable>
Print:<xsl:value-of select="label" /> <xsl:value-of
select="$optionText" />
</xsl:for-each>
(the thing is this loop is included in a bit more complex context
(wordml) - but for simplicity it is left out)
The problem I'm having with the above xslt is that when <data> has a
value my optionText-variable will run three times and that messes my
structure up. The variable does something strange it gets the value -
in the first example "No". But before and after there's a "gap" sort of
like it has gone through my loop and added some white space.
I don't know if this makes any scense. But I hope so. Maybe there's a
better way to do this?
Thanks in advance!
..christer