在XSL中使用XPath选择属性名称以给定字符串开头的节点的所有属性值
我有一些看起来像这样的 xml:
<row>
<anode myattr1="value1" anotherAttr="notthis">
blah
</anode>
<anothernode myattr1="value1" myattr2="value2" anotherAttr="notthis">
blahBlah
</anothernode>
</row>
我想变成这样的东西:
<tr>
<td title="value1">
blah
</td>
<td title="value1\nvalue2">
blahBlah
</td>
</tr>
所以我尝试使用“fn:starts-with”来选择这些属性值,但不太有效。这是我到目前为止所拥有的:
<xsl:for-each select="row">
<tr>
<xsl:for-each select="./*">
<xsl:variable name="title">
<xsl:for-each select="./@[fn:starts-with(name(),'myattr')]">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:variable>
<td title="$title"><xsl:value-of select="."/></td>
</xsl:for-each>
</tr>
</xsl:for-each>
但是当我运行这个时出现异常。任何帮助将不胜感激。
I have some xml which looks like this:
<row>
<anode myattr1="value1" anotherAttr="notthis">
blah
</anode>
<anothernode myattr1="value1" myattr2="value2" anotherAttr="notthis">
blahBlah
</anothernode>
</row>
I want to turn into something like this:
<tr>
<td title="value1">
blah
</td>
<td title="value1\nvalue2">
blahBlah
</td>
</tr>
So I'm trying to use the "fn:starts-with" to select these attribute values, but is not quite working. This is what I have so far:
<xsl:for-each select="row">
<tr>
<xsl:for-each select="./*">
<xsl:variable name="title">
<xsl:for-each select="./@[fn:starts-with(name(),'myattr')]">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:variable>
<td title="$title"><xsl:value-of select="."/></td>
</xsl:for-each>
</tr>
</xsl:for-each>
But am getting an exception when I run this. Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简短的转换:
应用于提供的 XML 文档时:
生成所需的正确结果:
A short and simple transformation:
when applied on the provided XML document:
the wanted, correct result is produced: