Xml XSLT:从嵌套节点构建字符串
我有这个嵌套节点的XML,我想从中构建一个字符串。我该怎么做 示例XML节点:Xml XSLT:从嵌套节点构建字符串,xml,xslt,traversal,Xml,Xslt,Traversal,我有这个嵌套节点的XML,我想从中构建一个字符串。我该怎么做 示例XML节点: <ND FID="22" FN=">" FC="Compare" DT="Greater Than" DTY="BOOL" CID="-1" PS="1" PF="ROOT" DN="True" GB="False" LK="False" PT="2"> <ND FID="176" FN="Add_Months" FC="Date and Time" DT="AddMo
<ND FID="22" FN=">" FC="Compare" DT="Greater Than" DTY="BOOL"
CID="-1" PS="1" PF="ROOT" DN="True" GB="False" LK="False" PT="2">
<ND FID="176" FN="Add_Months" FC="Date and Time" DT="AddMonths"
DTY="DATETIME" CID="-1" PS="1" PF=">" DN="False" GB="False"
LK="False" PT="2">
<ND FID="117" FN="TodayMinusDays" FC="Date and Time"
DT="TodayMinusDays" DTY="DATETIME" CID="-1" PS="1"
PF="Add_Months" DN="False" GB="False" LK="False" PT="2">
<ND FID="-1" FN="" FC="" DT="2" DTY="INTEGER" CID="5"
PS="1" PF="TodayMinusDays" DN="False" GB="False"
LK="False" PT="3"/>
</ND>
<ND FID="-1" FN="" FC="" DT="10" DTY="INTEGER" CID="3"
PS="2" PF="Add_Months" DN="False" GB="False" LK="False"
PT="3"/>
</ND>
<ND FID="-1" FN="" FC="" DT="DTTM" DTY="DATETIME" CID="4" PS="2"
PF=">" DN="False" GB="False" LK="False" PT="4"/>
</ND>
提前谢谢 我现在不能测试,但我想应该是这样的:
<xsl:apply-templates select="ND" />
<xsl:template match="ND">
<xsl:choose>
<xsl:when test="@FN!=''">
<xsl:value-of select="@FN" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@DT" />
</xsl:otherwise>
</xsl:choose>
(
<xsl:apply-templates select="ND" />
)
</xsl:template>
(
)
它看起来像一个解析器结果树。此样式表:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="ND[@FID > 0][@DN='True']">
<xsl:apply-templates select="*[1]"/>
<xsl:value-of select="concat(' ',@FN,' ')"/>
<xsl:apply-templates select="*[2]"/>
</xsl:template>
<xsl:template match="ND[@FID > 0][@DN='False']">
<xsl:value-of select="concat(@FN,'(')"/>
<xsl:for-each select="*">
<xsl:if test="position()!=1"> ,</xsl:if>
<xsl:apply-templates select="."/>
</xsl:for-each>
<xsl:text>)</xsl:text>
</xsl:template>
<xsl:template match="ND[0 > @FID]">
<xsl:value-of select="@DT"/>
</xsl:template>
</xsl:stylesheet>
注意:运算符、函数和数据规则。您所期望的结果以及应该实现的规则/约束/逻辑根本不清楚。更不用说没有名为
DTTM
的元素/属性了???请编辑您的问题,这次请定义好。谢谢大家的回答。:)
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="ND[@FID > 0][@DN='True']">
<xsl:apply-templates select="*[1]"/>
<xsl:value-of select="concat(' ',@FN,' ')"/>
<xsl:apply-templates select="*[2]"/>
</xsl:template>
<xsl:template match="ND[@FID > 0][@DN='False']">
<xsl:value-of select="concat(@FN,'(')"/>
<xsl:for-each select="*">
<xsl:if test="position()!=1"> ,</xsl:if>
<xsl:apply-templates select="."/>
</xsl:for-each>
<xsl:text>)</xsl:text>
</xsl:template>
<xsl:template match="ND[0 > @FID]">
<xsl:value-of select="@DT"/>
</xsl:template>
</xsl:stylesheet>
Add_Months(TodayMinusDays(2) ,10) > DTTM