我有一些XSLT用于选择具有特定关键字<sliceXML>
的文本。这样可以正常工作并依次抓取每个段落。我还想选择页面标记<pg>
的内容并显示它。
然而,它会继续选择第一个<pg>
标记的值,而不会移动到下一个标记。非常感谢任何帮助。
我的XML
<para>
<sliceXML>telescope</sliceXML>
A telescope test can be used to observe the night sky. What
observations can you make about the universe from your own back yard?
<pg>Page: 77</pg>
</para>
<para>
<sliceXML>telescope</sliceXML>
The scientists using the Sloan Digital Sky Survey telescope can
gather far more information than they can review quickly. Humans are
better at galaxy identification than computers. Why might this be a
difficult task for computers?
<pg>Page 78</pg>
</para>
注意:第77页和第78页
我的XSLT
<xsl:template name="para">
<div id="para">
<xsl:copy-of select="text()"/>
<span class="pagetag">
<xsl:value-of select="//pg"/><img src="images/arrows.png" height="12px"/>
</span>
</div>
</xsl:template>
我目前的结果
望远镜测试可用于观察夜空。您可以从自己的后院对宇宙做出什么观察? 页数:77
使用斯隆数字天空测量望远镜的科学家们可以收集到比他们快速检查的信息更多的信息。人类在星系鉴定方面比计算机更好。为什么这对计算机来说是一项艰巨的任务? 页数:77
我想要的结果
望远镜测试可用于观察夜空。您可以从自己的后院对宇宙做出什么观察? 页数:77
使用斯隆数字天空测量望远镜的科学家们可以收集到比他们快速检查的信息更多的信息。人类在星系鉴定方面比计算机更好。为什么这对计算机来说是一项艰巨的任务? Page:78
由于
答案 0 :(得分:1)
也许您应该尝试pg
而不是//pg
?因为您想要pg
的孩子para
。
答案 1 :(得分:0)
已经有一段时间了,但也许.//pg而不是// pg
答案 2 :(得分:0)
以下作品对我来说很好
<强> XML:强>
<form>
<para>
<sliceXML>telescope</sliceXML>
A telescope test can be used to observe the night sky. What
observations can you make about the universe from your own back yard?
<pg>Page: 77</pg>
</para>
<para>
<sliceXML>telescope</sliceXML>
The scientists using the Sloan Digital Sky Survey telescope can
gather far more information than they can review quickly. Humans are
better at galaxy identification than computers. Why might this be a
difficult task for computers?
<pg>Page 78</pg>
</para>
</form>
<强> XSL:强>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"
xmlns:date="http://exslt.org/dates-and-times" xmlns:str="http://exslt.org/strings">
<xsl:template match="form/para">
<div id="para">
<xsl:copy-of select="text()"/>
<span class="pagetag">
<xsl:value-of select="pg"/><img src="images/arrows.png" height="12px"/>
</span>
</div>
</xsl:template>
</xsl:stylesheet>
<强>输出:强>
<?xml version="1.0" encoding="UTF-8"?>
<div xmlns="http://www.w3.org/1999/xhtml" xmlns:date="http://exslt.org/dates-and-times" xmlns:str="http://exslt.org/strings" id="para">
A telescope test can be used to observe the night sky. What
observations can you make about the universe from your own back yard?
<span class="pagetag">Page: 77<img src="images/arrows.png" height="12px"/></span></div>
<div xmlns:date="http://exslt.org/dates-and-times" xmlns:str="http://exslt.org/strings" xmlns="http://www.w3.org/1999/xhtml" id="para">
The scientists using the Sloan Digital Sky Survey telescope can
gather far more information than they can review quickly. Humans are
better at galaxy identification than computers. Why might this be a
difficult task for computers?
<span class="pagetag">Page 78<img src="images/arrows.png" height="12px"/></span></div>