XSLT 获取最后一个节点名称
XSLT Get last node name
你好,有这个 XML 例如:
<Message>
<Ship>
<ShipSummary>
<ComName>XPTO 123</ComName>
<FacName>6</FacName>
</ShipSummary>
</Ship>
</Message>
</tXML>
我需要提取 header 'ComName' 例如。
然后我尝试使用此代码:
<!-- -->
<xsl:template match="text()" mode="header">
<xsl:for-each select="ancestor::*">
<xsl:choose>
<!-- avoid beginning slash (at root) -->
<xsl:when test="position() = 1">
<xsl:value-of select="local-name()" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('/',local-name())" />
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:value-of select="$delim"/>
<!-- <xsl:apply-templates select="node()" /> -->
</xsl:template>
结果是:
| Message/Ship/ShipSummary/ComName | Message/Ship/ShipSummary/FacName |
| ------ | -------------- |
| XPTO 123 | 6 |
我需要这个;
|通讯名|假名 |
| ------ | -------------- |
| XPTO 123 | 6 |
有什么想法吗?
AFAICT,你只需要做:
<xsl:template match="text()" mode="header">
<xsl:value-of select="local-name(..)" />
<xsl:value-of select="$delim"/>
</xsl:template>
未测试,因为没有提供测试代码。
你好,有这个 XML 例如:
<Message>
<Ship>
<ShipSummary>
<ComName>XPTO 123</ComName>
<FacName>6</FacName>
</ShipSummary>
</Ship>
</Message>
</tXML>
我需要提取 header 'ComName' 例如。
然后我尝试使用此代码:
<!-- -->
<xsl:template match="text()" mode="header">
<xsl:for-each select="ancestor::*">
<xsl:choose>
<!-- avoid beginning slash (at root) -->
<xsl:when test="position() = 1">
<xsl:value-of select="local-name()" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('/',local-name())" />
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:value-of select="$delim"/>
<!-- <xsl:apply-templates select="node()" /> -->
</xsl:template>
结果是: | Message/Ship/ShipSummary/ComName | Message/Ship/ShipSummary/FacName | | ------ | -------------- | | XPTO 123 | 6 |
我需要这个; |通讯名|假名 | | ------ | -------------- | | XPTO 123 | 6 |
有什么想法吗?
AFAICT,你只需要做:
<xsl:template match="text()" mode="header">
<xsl:value-of select="local-name(..)" />
<xsl:value-of select="$delim"/>
</xsl:template>
未测试,因为没有提供测试代码。