当前位置: 首页 > 知识库问答 >
问题:

使用XSL更改输出XML值

蔚和安
2023-03-14
<?xml version="1.0" encoding="UTF-8"?>
<Person>
        <lookuptable>
          <name first="Jen" ori="Jenny" />
          <name first="Sam" ori="Sammy" />
        </lookuptable>
    <Student>
        <Info Name="Jen" Age="20" Class="C" />
    </Student>
    <Student>
        <Info Name="Sam" Age="21" Class="B" />

    </Student>

</Person>
<?xml version="1.0" encoding="UTF-8"?>
<Person>
        <lookuptable>
          <name first="Jen" ori="Jenny" />
          <name first="Sam" ori="Sammy" />
        </lookuptable>
    <Student>
        <Info Name="Jenny" Age="20" Class="C" />
    </Student>
    <Student>
        <Info Name="Sammy" Age="21" Class="B" />

    </Student>

</Person>

如何从lookuptable中获取Jenny、Sammy等??这意味着每个发生jen的地方都应该使用表中的jenny。我不知道如何编写XSL。

共有1个答案

张晔
2023-03-14
<xsl:key name="k1" match="lookuptable/name" use="@first"/>


<xsl:template match="@* | node()">
  <xsl:copy>
    <xsl:apply-templates select="@* , node()"/>
  </xsl:copy>
</xsl:template>


<xsl:template match="Student/Info/@Name">
  <xsl:attribute name="{name()}" select="key('k1', .)/@ori"/>
</xsl:template>
 类似资料:
  • 我有以下结构:

  • 问题内容: 我想以类似于http://www.google.com/ig/api?weather=Mountain+View的方式输出原始xml,但使用PHP。 我的网络服务器上有一个非常简单的php脚本: 我在Chrome / firefox中只能看到“ sample_name”。我想看看: 我找不到简单的教程。 谢谢 问题答案: 默认情况下,PHP将Content-Type设置为text /

  • 我必须在这个xml中设置“count”属性的值: 我想使用这样的代码(VTDXML库)使用“Foo”更改myCount值: 这样我反而获得了 那不是我的目标因为我想要的是

  • 科特林: 这让我对一些后期编译任务感到头疼。如何配置Kotlin以将类文件生成到不同的目录中?

  • 我是XSLT新手。我想根据其他子节点的条件更改XML中的根节点。但子节点始终保持不变。例如,我有以下XML: 我喜欢将XML更改为: 这意味着依赖于<代码> 我不想在每个<代码>