使用XSL将XML属性作为ID传递给HTML [英] Using XSL to pass an XML attribute as an id into HTML

查看:113
本文介绍了使用XSL将XML属性作为ID传递给HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望你能帮助指出我正确的方向与这个问题...

我正在做的事:
我有一个XML文件我正在使用XSLT转换为HTML。其中的一部分包括添加一个隐藏按钮。我想使用隐藏按钮从XML中删除节点,我的想法是为该按钮提供与相关XML元素中的myId属性相同的id,这使得可以轻松地将按钮的onClick与XML匹配

以下是一些XML: < sectionStatement myId =1> Awesome statement< / sectionStatement>
< sectionStatement myId =2>我是一个声明< / sectionStatement>
< sectionStatement myId =3>我是另一个声明< / sectionStatement>

以下是我坚持使用的XSL:

 < xsl:for-each select =sectionStatement> 
< p>< xsl:value-of select =。/>< a class ='showHideBtn'href ='#'>隐藏< / a>< / p>
< / xsl:for-each>

...所以我想结束3段html,每段都有一个隐藏按钮,我希望按钮具有相关的ID(1,2或3)。它相当于将 id =< xsl:value-of select ='@ myId'/>添加到标签中,但我试过了

感谢您的建议:-)
马克

解决方案

使用属性值模板< a id ={@ myId}class =showHideBtnhref =#>隐藏< / a> / code>。


Hope you can help point me in the right direction with this problem...

What I am trying to do: I have an XML file that I'm turning into HTML using XSLT. Part of that includes adding a "hide" button. I want to use the hide button to remove the node from the XML, and my idea is to give the button the same id as the myId attribute in the relevant XML element, which makes it easy to match the onClick of the button with the XML element to hide.

Here's a bit of the XML:

<sectionStatement myId="1">Awesome statement</sectionStatement>
<sectionStatement myId="2">I am a statement</sectionStatement>
<sectionStatement myId="3">I am another statement</sectionStatement>

Here's a bit of the XSL where I' stuck:

<xsl:for-each select="sectionStatement">
  <p><xsl:value-of select="."/><a class='showHideBtn' href='#'>Hide</a></p>
</xsl:for-each>

...so I want to end up with 3 paras of html, each with a "Hide" button, and I want the button to have the relevant id (1,2 or 3). It is the equivalent of adding id="<xsl:value-of select='@myId'/>" into the tag ...but I've tried that and it doesn't work!

Thanks for your advice :-) Mark

解决方案

Use an attribute value template <a id="{@myId}" class="showHideBtn" href="#">Hide</a>.

这篇关于使用XSL将XML属性作为ID传递给HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆