I have a scenario like this in xml:
<ViewFields>
<FieldRef Name="Planing Status" />
<FieldRef Name="Resource Statu开发者_Go百科s" />
<FieldRef Name="Development Status" />
<FieldRef Name="Testing Status" />
</ViewStatus>
I have to loop through this in xsl, I followed below:
<xsl:template name="FieldRef_body.Status" match="FieldRef[@Name=/ViewFields/FieldRef[1]]" mode="body">
IT'S NOT RETURNING ANY THING @Name variable i am using several places in this section. I want to assign FieldRef values to @Name variable through loop.
<xsl:template name="FieldRef_body.Status"
match="FieldRef[@Name=/ViewFields/FieldRef[1]]" mode="body">
There are two things to note here:
The match attribute contains an XPath expression that, when applied on the provided XML document, selects no node at all. It is supposed to select an element named
FieldRef
the string value of whoseName
attribute is equal to the string value of the firstFieldRef
child of theViewFields
top element. However, none of theFieldRef
elements in the XML document have any (non-empty) string value. On the other side, the string values of allName
attributes are non-empty. My guess is that you wanted:match="FieldRef[@Name=/ViewFields/FieldRef[1]/@Name]"
Any template in a (non-anonymous) mode isn't considered by the XSLT processor for selection if its mode is different from the current mode.
As the initial mode in XSLT 1.0 (and in XSLT 2.0) is the empty (anonymous) mode, the only way to make a template in a non-anonymous mode considered for selection is to explicitly specify the mode on an <xsl:apply-templates>
instruction.
This transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:apply-templates select="*/*" mode="body"/>
</xsl:template>
<xsl:template match="FieldRef[@Name=/ViewFields/FieldRef[1]/@Name]"
mode="body">
<xsl:value-of select="@Name"/>
</xsl:template>
</xsl:stylesheet>
produces this result, showing that the template is selected for processing:
Planing Status
精彩评论