xml - 如何从键函数(XSLT)中选择要返回的元素
问题描述
我的 XML 文件如下所示:
<Geometry>
<Shapes>
<Shape id="b1" author-id="a1">
<width>First</width>
<height>Shape</height>
<color>Color</color>
<Shape id="b2" author-id="a2">
<width>Second</width>
<height>Shape</height>
<color>Color</color>
</Shape>
</Shapes>
<Authors>
<Author id="b1">
<name>Andrew</name>
<secondname>Coldwater</secondname>
<tel>978-3-16-148410-0</tel>
</Author>
<Author id="b2">
<name>Andrew</name>
<secondname>Coolwater</secondname>
<tel>9781-140-201</tel>
</Author>
</Author>
当我使用
<xsl:key name="exampleName" match="Author" use="@id"/>
和
<xsl:apply-templates select="key('exampleName', @author-id)" />
在返回时,我拥有作者的所有属性。我需要做的是只接收名字和第二个名字。也许这是一个微不足道的问题,但我找不到答案......或者我不知道如何问:)
解决方案
使用模板匹配Author
来自<xsl:apply-templates select="key('exampleName', @author-id)" />
.
像
<xsl:template match="Author">
<xsl:value-of select="name" />
<xsl:value-of select="secondname" />
</xsl:template>
推荐阅读
- javascript - array.include 是否适用于嵌套对象
- javascript - ChartJS:在 y 轴上带有标签的折线图
- kotlin - 通过 Kotlin 中任意集合的排列逐步迭代
- dependency-injection - 如何在运行时解析参数化类?
- flutter - App被杀死时如何保存更改?
- c# - 我需要在 c#winform 应用程序中跟踪赛道,我可以在上面添加和移动点,但找不到任何教程
- javascript - C# 的 JSON 结果不适用于 Chart.js
- node.js - 续集,检查行是否存在并返回布尔值
- regex - PowerShell如何在特定模式之后捕获文本字符串但不将模式本身包含在结果中
- android - 安装firebase插件后使用cordova运行应用程序时编译错误