需要从递归XML结构的所有级别提取值。所有级别的结构都是相同的
<regPackagingHierarchyList>
<RegistrationPackagingHierarchy>
<recordId>Level0</recordId>
<regParentPackagingHierarchy>
<RegistrationPackagingHierarchy>
<recordId>level5</recordId>
<regParentPackagingHierarchy>
<RegistrationPackagingHierarchy>
<recordId>level4</recordId>
<regParentPackagingHierarchy>
<RegistrationPackagingHierarchy>
<recordId>level3</recordId>
<regParentPackagingHierarchy>
<RegistrationPackagingHierarchy>
<recordId>level2</recordId>
<regParentPackagingHierarchy>
<RegistrationPackagingHierarchy>
<recordId>level1</recordId>
</RegistrationPackagingHierarchy>
</regParentPackagingHierarchy>
</RegistrationPackagingHierarchy>
</regParentPackagingHierarchy>
</RegistrationPackagingHierarchy>
</regParentPackagingHierarchy>
</RegistrationPackagingHierarchy>
</regParentPackagingHierarchy>
</RegistrationPackagingHierarchy>
</regParentPackagingHierarchy>
</RegistrationPackagingHierarchy>
</regPackagingHierarchyList>
预期结果应采用以下格式 级别1,级别2,级别3,级别4,级别5
答案 0 :(得分:3)
1.0中的一种方法可以是:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" />
<xsl:template match="/">
<xsl:for-each select="//regParentPackagingHierarchy//recordId">
<xsl:sort select="position()" order="descending" />
<xsl:value-of select="." />
<xsl:if test="position() != last()">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
http://xsltfiddle.liberty-development.net/pPzifpv
编辑:
<xsl:value-of select="concat('Count(regPackagingHierarchyList) = ', count(//regPackagingHierarchyList))"/>
<xsl:value-of select="concat('Count(RegistrationPackagingHierarchy) = ', count(//RegistrationPackagingHierarchy))"/>
编辑2:
答案 1 :(得分:0)
<xsl:template match="*">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="recordId">
<xsl:apply-templates/>
<!-- Apply all the templates beneath first and output your id after they got applied. -->
<xsl:if test="ancestor::regParentPackagingHierarchy">
<xsl:value-of select="."/>
</xsl:if>
</xsl:template>