I have a loop in xsl and depending upon the attribute value, i want to write some text.
XML is as follows:
<ROWS><ROW oid="28439"><EFL eid="8" fid="27672" count="2">
<MK id="3" val="0"/>
<MK id="11" val="0578678 "/> </ROW></ROWS>
开发者_如何学GoXSL is as follows:
<xsl:for-each select="EFL/MK">
<xsl:value-of select="@id" />:
<xsl:value-of select="@val" />
</xsl:for-each>
I want to have the following output:
3:0 & 11:057868"&" is needed if there are more than one "MK" tags. Count of "MK" tags is available in "Count" attribute of "Row" tag.
Can you please tell me how to put the following if condition in XSL:
if Count Atrribute available in Row tag has a value greater than 1 Then Display "&" EndIF
Thanks
This transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:template match="ROWS/ROW">
<xsl:for-each select="EFL/MK">
<xsl:value-of select=
"concat(substring(' & ', 1 div (position() > 1)),
@id,
':',
@val,
substring('
', 1 div (position() = last()))
)
"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
when applied on the provided XML document (corrected to be well-formed):
<ROWS>
<ROW oid="28439">
<EFL eid="8" fid="27672" count="2">
<MK id="3" val="0"/>
<MK id="11" val="0578678"/>
</EFL>
</ROW>
</ROWS>
produces the wanted, correct result:
3:0 & 11:0578678
Try this code:
<xsl:for-each select="EFL/MK">
<xsl:value-of select="@id" />:
<xsl:value-of select="@val" />
<xsl:if test="../@count > 1">
<xsl:if test="not(position()=last())"><![CDATA[ & ]]></xsl:if>
</xsl:if>
</xsl:for-each>
精彩评论