这里sort via xpath和这里Grouping using the Münchian Method都进行了研究,但是找不到适合我的情况的sort on 'fieldValue' for 'Label' inside 'userField[23]', inside 'SysStructure_FIELD[146]'
这是我的xslt:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*" />
<xsl:output method="xml" indent="yes" />
<xsl:template match="/Root/STRUCTURESet/STRUCTURE/userField[2]/STRUCTURE_Fields/SysStructure_FIELD">
<xsl:copy>
<xsl:apply-templates select="objectId"/>
<xsl:apply-templates select="userField">
<xsl:sort select="fieldLabel[10]/fieldValue" data-type="text" order="ascending"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
所需的输出:无法对fieldValue的Labels进行排序。 你能帮忙吗?
xml的缩写形式在下面('userField(3)',在'SysStructure_FIELD(3)'内):
<Root version="1-1">
<STRUCTURESet>
<STRUCTURE id="STRUCTURE_0">
<objectId class="STRUCTURE">
<identifier>49</identifier>
<primarySystem>Sys</primarySystem>
<label>Sys_Default_Structure</label>
</objectId>
<userField>
<fieldLabel>Description</fieldLabel>
<fieldValue>Sys Default structure level</fieldValue>
<fieldType>character</fieldType>
</userField>
<userField>
<fieldLabel>Fields</fieldLabel>
<STRUCTURE_Fields>
<SysStructure_FIELD>
<objectId class="SysStructure_FIELD">
<primarySystem>Sys</primarySystem>
</objectId>
<userField>
<fieldLabel>Hide</fieldLabel>
<fieldValue>0</fieldValue>
<fieldType>numeric</fieldType>
</userField>
<userField>
<fieldLabel>Label</fieldLabel>
<fieldValue>System_value</fieldValue>
<fieldType>character</fieldType>
</userField>
<userField>
<fieldLabel>MainReturn</fieldLabel>
<fieldValue/>
<fieldType>character</fieldType>
</userField>
</SysStructure_FIELD>
<SysStructure_FIELD>
<objectId class="SysStructure_FIELD">
<primarySystem>Sys</primarySystem>
</objectId>
<userField>
<fieldLabel>Hide</fieldLabel>
<fieldValue>0</fieldValue>
<fieldType>numeric</fieldType>
</userField>
<userField>
<fieldLabel>Label</fieldLabel>
<fieldValue>Off_Market</fieldValue>
<fieldType>character</fieldType>
</userField>
<userField>
<fieldLabel>MainReturn</fieldLabel>
<fieldValue/>
<fieldType>character</fieldType>
</userField>
</SysStructure_FIELD>
<SysStructure_FIELD>
<objectId class="SysStructure_FIELD">
<primarySystem>Sys</primarySystem>
</objectId>
<userField>
<fieldLabel>Hide</fieldLabel>
<fieldValue>0</fieldValue>
<fieldType>numeric</fieldType>
</userField>
<userField>
<fieldLabel>Label</fieldLabel>
<fieldValue>System_Time</fieldValue>
<fieldType>character</fieldType>
</userField>
<userField>
<fieldLabel>MainReturn</fieldLabel>
<fieldValue/>
<fieldType>character</fieldType>
</userField>
</SysStructure_FIELD>
</STRUCTURE_Fields>
</userField>
<userField>
<fieldLabel>Label</fieldLabel>
<fieldValue>Sys_Default_Structure</fieldValue>
<fieldType>character</fieldType>
</userField>
</STRUCTURE>
</STRUCTURESet>
答案 0 :(得分:0)
因为在结构中提到了两次userField,所以您需要确切指定要检查的字段:userField / fieldLabel [text()='Label'而不是userField / fieldLabel [10] 此外,您需要在与fieldLabel相同的级别上进行排序:../fieldValue正在执行此工作。
所以完整的陈述是:
<xsl:template match="/Root/STRUCTURESet/STRUCTURE/userField[2]/STRUCTURE_Fields">
<xsl:copy>
<xsl:apply-templates select="SysStructure_FIELD">
<xsl:sort select="userField/fieldLabel[text()='Label']/../fieldValue" />
</xsl:apply-templates>