遍历XSL中的XML元素 [英] Loop through XML elements in XSL
本文介绍了遍历XSL中的XML元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在这样的XML文件中
I have in XML file like this
<ViewFields>
<FieldRef Name="Approval Status" />
<FieldRef Name="Requirement Status" />
<FieldRef Name="Development Status" />
<FieldRef Name="Testing Status" />
</ViewStatus>
我有以下XSL代码来获取FieldRef值.
I have the following XSL code to get FieldRef values.
<xsl:template name="FieldRef_body.Status" match="FieldRef[@Name='ViewFields/FieldRef[1]/@Name']" mode="body">
<xsl:param name="thisNode" select="."/>
<xsl:choose>
<xsl:when test="$thisNode/@*[name()=current()/@Name] = 'Completed'">
<img src="/_layouts/images/IMNON.png" alt="Status: {$thisNode/@Status}"/>
</xsl:when>
<xsl:when test="$thisNode/@*[name()=current()/@Name] = 'In Progress'">
<img src="/_layouts/images/IMNIDLE.png" alt="Status: {$thisNode/@Status}"/>
</xsl:when>
<xsl:otherwise>
<img src="/_layouts/images/IMNBUSY.png" alt="Status: {$thisNode/@Status}"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
我试图通过FieldRef * [x] *进行遍历以逐个获取值,但没有返回任何内容.我想通过循环将FieldRef值分配给@Name变量.
I am trying to LOOP through FieldRef*[x]* to get the values one by one, it's not returning anything. I want to assign FieldRef values to @Name variable through loop.
推荐答案
您的问题并不具有正确回答所需的所有上下文,但是您应该考虑将构造简化为"for-each"以进行循环
Your question doesn't have all of the context needed to answer correctly, but you should consider simplifying your construct down to a "for-each" for your looping.
提供xml
<ViewFields>
<FieldRef Name="Approval Status" />
<FieldRef Name="Requirement Status" />
<FieldRef Name="Development Status" />
<FieldRef Name="Testing Status" />
</ViewFields>
使用xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="main" match="/">
<xsl:for-each select="/ViewFields/FieldRef">
<xsl:choose>
<xsl:when test="@Name = 'Approval Status'">
<ApprovalStatus/>
</xsl:when>
<xsl:when test="@Name = 'Requirement Status'">
<RequirementStatus/>
</xsl:when>
<xsl:otherwise>
<SomethingElse/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
这可能会更接近您想要的东西.
This might be a bit closer to what you were wanting.
这篇关于遍历XSL中的XML元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文