xslt - 如何连接父节点的属性名称

标签 xslt

我有一个这样的 XML 文档:

<Module Name="DacInPlaceUpgradeLtmTest" Desc="" >
 <TestCase Name="ExecuteInPlaceUpgradeTest">
  <TestCase Name="BugRepro">
   <TestCase Name="295130">
      <Variation Id="1" Desc="Sql - EmptyAlterScript">
      <Variation Id="2" Desc="Sql - EmptyDatabase">
   </TestCase>
  </TestCase>
 </TestCase>
</Module>

我使用 xsl 来获取一个值:
ExectionInplaceUPgradeTest BugRepro 295130 

通过使用以下模板:
 <xsl:template match="TestCase//Variation">
    <xsl:for-each select="..@Name">

今天只能拿到295130,不知道怎么才能拿到TestCase父节点的所有属性。

最佳答案

I wonder how can I get all Attributes of the parent nodes which is TestCase



您可能需要 XPath ancestor-or-self轴:
ancestor-or-self::TestCase/@Name

how to concat the attribte names of the parent nodes



这实际上取决于模板上下文和您已经在处理的代码。以您的片段作为引用,我会写得更好:
<xsl:template match="TestCase[Variation]">
    <xsl:for-each select="ancestor-or-self::TestCase/@Name">
        <xsl:value-of select="concat(.,' ')"/>
    </xsl:for-each>
</xsl:template>

这将打印从 TestCase 开始的想要的字符串具有 Variation 的节点作为 child 的节点。

关于xslt - 如何连接父节点的属性名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6643816/

相关文章:

xslt - 计算 <call-template> 返回的元素数量

xml - XSLT - 将 namespace 添加到输出

xml - 我怎样才能得到第一个更高级别的字符串?

xml - XSLT 映射算法

html - Qt4中XSLT转HTML,key函数不可用

XSLT 键()查找

php - 有没有人从 PHP 模板转到 XSLT 模板并且不后悔?

html - XSLT 在编码符号时使用 HTML 数字而不是 HTML 名称?

xslt 中的 XML 命名空间处理

java - 使用 STaX 将一个 xml 转换为另一个 xml 需要花费大量时间