0

我有一些 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

使用斯隆数字巡天望远镜的科学家们可以收集到比他们快速查看更多的信息。人类比计算机更擅长星系识别。为什么这对计算机来说可能是一项艰巨的任务?页数:78

谢谢

4

3 回答 3

1

也许你应该尝试pg而不是//pg?因为你想要pg那个是你的孩子para

于 2012-10-05T16:39:31.277 回答
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>
于 2012-10-05T16:46:30.037 回答
0

已经有一段时间了,但也许是 .//pg 而不是 //pg

于 2012-10-05T16:40:59.657 回答