Xslt提取属性并生成html
我正在尝试将以下 XML.. 转换
<?xml version="1.0" encoding="utf-16"?><Member TextRank="unknown" FullName="My Name" ..etc.. />
为类似以下内容,
<div class="member">
<span class="label">
Text Rank (note: i want to override the labels in the xslt)
</div>
<span class="value">
unknown
</span>
<span class="label">
Full Name
</div>
<span class="value">
My Name
</span>
..etc..
</div>
如果可能的话,我如何使用 xslt 来完成此操作?
I'm trying to transform the following XML..
<?xml version="1.0" encoding="utf-16"?><Member TextRank="unknown" FullName="My Name" ..etc.. />
Into something like the following,
<div class="member">
<span class="label">
Text Rank (note: i want to override the labels in the xslt)
</div>
<span class="value">
unknown
</span>
<span class="label">
Full Name
</div>
<span class="value">
My Name
</span>
..etc..
</div>
How if possible could I do this using xslt?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一种不同的方法,它消除了对 xsl:choose 元素的需要。相反,您可以利用匹配模板为您想要覆盖的属性名称的情况提供特定模板,并为其他情况提供通用模板。
为了避免重复代码,您还可以使通用模板成为命名模板,并使用参数来覆盖名称。
因此,大多数属性的默认值是使用属性名称,但特定模板为 @FullName< /strong> 然后可以用不同的名称来调用它。
以下是完整的 XSLT:
当应用于以下 XML 时:
输出如下:
Here's a different approach, that does away for the need for the xsl:choose element. Instead, you could take advantage of the matching templates to have specific templates for the cases of attributes who names you want to override, and a generic template for other case.
To avoid repetition of code, you could also make the generic template a named template, with a parameter to override the name
So, the default for most attributes would be to use the attribute name, but the specific template for @FullName could then call this with a different name.
Here is the full XSLT:
When applied to the following XML:
The following is output:
这是我想出的解决方案。
This is the solution I came up with.