xml - 如何在 xsl 文件中的另一个匹配中调用一个匹配
问题描述
输入 :
首先dto:
- 链接:google.com
- 名称:谷歌
次要
- 链接:yahoo.com
- 名称:雅虎
<sites>
<firstdto>
<link>google.com</link>
<name>google</name>
</firstdto>
<seconddto>
<link>yahoo.com</link>
<name>yahoo</name>
</seconddto>
</sites>
预期输出:
google.com
yahoo.com
google
<body>
<link>google.com</link>
<link>yahoo.com</link>
<name>google</name>
</body>
输出电流:
google.com
google.com
google
注意:我只想seconddto
在firstdto
. 因为我想seconddto
在第一个属性中使用属性。但我无法做到这一点。firstdto
即使我将模板匹配到seconddto
.
有人可以帮我弄这个吗。这对我真的很有帮助。提前致谢。
<xsl:stylesheet>
<Xsl:template match="/">
<head>
<style>
.....
</style>
</head>
<body>
<xsl:apply-templates select="firstdto"/>
<xsl:apply-templates select="seconddto"/>
</body>
</xsl:template>
<xsl:template match="firstdto">
<body>
<xsl:value-of select="link"/>
<xsl:template match="seconddto">
<body>
<xsl:value-of select="link"/>
</body>
</xsl:template>
<xsl:value-of select="name">
</body>
</xsl:template>
解决方案
我只想
seconddto
在里面导入函数firstdto
。因为我想seconddto
在第一个属性中使用属性。
如果你想使用seconddto
里面的值firstdto
,那么你可以试试这个:
<xsl:template match="/sites">
<html>
<head>
<style>.....</style>
</head>
<body>
<xsl:apply-templates select="firstdto"/>
</body>
</html>
</xsl:template>
<xsl:template match="firstdto">
<xsl:copy-of select="link"/>
<xsl:copy-of select="../seconddto/link"/><!-- to use/copy value from other -->
<xsl:copy-of select="name"/>
</xsl:template>
获得如下输出:
<html>
<head>
<style>.....</style>
</head>
<body>
<link>google.com</link>
<link>yahoo.com</link>
<name>google</name>
</body>
</html>
推荐阅读
- javascript - NgRx 选择器在状态发生任何变化/选择器的记忆不起作用时发出
- javascript - 为什么信息框无法在谷歌地图模式窗口中正确加载?
- django - 如何在 CreatView 中获取对象
- javascript - 如何修复“无法解析 ComponentName 的所有参数”
- maven - 从maven项目中获取jar
- node.js - json-server 不使用中间件文件中提供的代码
- javascript - 当表单下载目标为此 iFrame 的文件时,未调用 iFrame onload
- django - 在视图中设置存储桶 Django google storage
- php - 如何在laravel中修改eloquent返回的数组结构
- python - 使用python编写csv文件时如何添加标题