转换内容位于 CDATA 内的 xml 元素
我有一个像下面这样的 xml 片段
<Detail uid="6">
<![CDATA[
<div class="heading">welcome to my page</div>
<div class="paragraph">this is paraph</div>
]]>
</Detail>
,我希望能够更改
<div class="heading">...</div> to <h1>Welcome to my page</h1>
<div class="paragraph">...</div> to <p>this is paragraph</p>
你知道我如何在 xslt 1.0 中做到这一点吗
I have a xml fragment like below
<Detail uid="6">
<![CDATA[
<div class="heading">welcome to my page</div>
<div class="paragraph">this is paraph</div>
]]>
</Detail>
and I want to be able to change the
<div class="heading">...</div> to <h1>Welcome to my page</h1>
<div class="paragraph">...</div> to <p>this is paragraph</p>
do you know how I can do that in xslt 1.0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
运行两个转换怎么样?
通过 1.)
将产生:
通过 2.)
产生:
What about running two transforms.
Pass 1.)
Will produce:
Pass 2.)
Produces:
您无法告诉 XSL 1.0 从 CDATA 中获取字符串并将其解析为 XML。
You cannot tell XSL 1.0 to fish a string out of a CDATA and parse it as XML.
您无法“删除”CDATA,但您可以粗略地实现所需的输出:
这适用于您尝试解析的第一种类型的 div,并且您可以对第二种类型进行类似的操作。经过一些努力,它可以变得更加通用。
You can't "remove" the CDATA, but you can achieve the desired output somewhat crudely:
This will work for the first type of div you're trying to parse and you can follow something similar with the second one. It could be made more generic with some effort.