Variables 在谓词中使用变量值时,XSL document()函数不起作用
我有两个xml文档:Variables 在谓词中使用变量值时,XSL document()函数不起作用,variables,xslt,document,predicate,Variables,Xslt,Document,Predicate,我有两个xml文档: 包含小型内联img的技术文章 一个包含img的文件,img是本文中小图像的全尺寸版本。我把这个文件称为“副文件” 我的目标是使用xsl来更新本文中的xml,这样,我就不用为每个图使用一个img,而是使用两个img。。。小的一个最初在xml文章中编码,相应的大的一个。这两个img都是一个新元素image set的子元素 下面是“之前”和“之后”的情况: 之前: <figure> <heading alttoc="" refname="fig1" typ
<figure>
<heading alttoc="" refname="fig1" type="figure">Figure 1. netserver on SUT in out
of the box configuration</heading>
<img alt="netserver on SUT in out-of-the-box configuration"
height="288" src="figure1.jpg" width="572"/>
</figure>
图1。SUT输入输出上的netserver
盒子的配置
之后:
<figure>
<heading alttoc="" refname="fig1" type="figure">Figure 1. netserver on SUT in out
of the box configuration</heading>
<image-set>
<img alt="netserver on SUT in out-of-the-box configuration"
height="288" src="figure1.jpg" width="572"/>
<img alt="netserver on SUT in out-of-the-box configuration"
height="456" src="figure1_ian.jpg" width="905"/>
<!--The figureNumber is: 1-->
</image-set>
</figure>
图1。SUT输入输出上的netserver
盒子的配置
另一个XSL将更新的文章XML文件转换为HTML。较小的img将像以前一样以内联方式显示,但当用户单击“查看全尺寸版本”链接时,较大的img将以覆盖方式显示
问题描述:
每篇文章可以包含许多图像。每个边文件可以包含许多图像。我必须将侧文件中的正确图像与文章文件中的图像进行匹配。我正在使用xsl:number创建一个变量,为每个img存储一个与每个图像在文章文件中出现的顺序相对应的数字,并尝试在document()函数中引用该变量作为谓词,以在侧文件中获得正确的img。它不起作用:
以下是用于存储订单的变量:
<xsl:variable name="figureNumber">
<xsl:number />
</xsl:variable>
下面是document()函数的代码,该函数不适用于变量:
<!-- Output the larger version of the same img that sits in the sidefile.
The "/" as the second argument causes processor to look for the sidefile
in same folder as the article xml file. -->
<xsl:copy-of select="document('sidefile.xml',/)//figure[$figureNumber]/img" />
<xsl:comment>The figureNumber is: <xsl:value-of select="$figureNumber"/></xsl:comment>
具体数字如下:
当我运行此操作时,我没有从侧文件中获取我想要的img(在上面的示例中,我应该只获取第一个图像,或img[1]),而是获取侧文件中的所有img:
<figure>
<heading alttoc="" refname="fig1" type="figure">Figure 1. netserver on SUT in out
of the box configuration</heading>
<image-set>
<img alt="netserver on SUT in out-of-the-box configuration"
height="288" src="figure1.jpg" width="572"/>
<img alt="netserver on SUT in out-of-the-box configuration"
height="456" src="figure1_ian.jpg" width="905"/>
<img alt="netperf on SUT in out-of-the-box configuration"
height="456" src="figure2_ian.jpg" width="905"/>
<img alt="netperf and netserver (bidirectional) on SUT out of the box"
height="456" src="figure3_ian.jpg" width="905"/>
<img alt="netserver, out of the box with numactl"
height="456" src="figure4_ian.jpg" width="905"/>
<img alt="netperf, out of the box with numactl"
height="456" src="figure5_ian.jpg" width="905"/>
<img alt="netperf and netserver (bidirectional), out of the box with numactl"
height="456" src="figure6_ian.jpg" width="905"/>
<img alt="netserver, Ethernet SMP IRQ affinity, no irqbalance"
height="456" src="figure7_ian.jpg" width="905"/>
<img alt="netperf, Ethernet SMP IRQ affinity, no irqbalance"
height="456" src="figure8_ian.jpg" width="905"/>
<img alt="netperf and netserver (bidirectional), Ethernet SMP IRQ affinity, no irqbalance"
height="456" src="figure9_ian.jpg" width="905"/>
<img alt="netserver, Ethernet SMP IRQ affinity and numactl, no irqbalance"
height="456" src="figure10_ian.jpg" width="905"/>
<img alt="netperf, Ethernet SMP IRQ affinity and numactl, no irqbalance"
height="456" src="figure11_ian.jpg" width="905"/>
<img alt="Bidirectional, Ethernet SMP IRQ affinity and numactl, no irqbalance"
height="456" src="figure12_ian.jpg" width="905"/>
<img alt="netserver, Ethernet SMP IRQ affinity, no irqbalance, bonded interfaces"
height="456" src="figure13_ian.jpg" width="905"/>
<img alt="netserver, Ethernet SMP IRQ affinity, no irqbalance, with and without bonding"
height="456" src="figure14_ian.jpg" width="905"/>
<!--The figureNumber is: 1-->
</image-set>
</figure>
<figure>
<heading alttoc="" refname="fig1" type="figure">Figure 1. netserver on SUT in out
of the box configuration</heading>
<img alt="netserver on SUT in out-of-the-box configuration" height="456" src="figure1_ian.jpg" width="905"/>
</figure>
<!-- Spacer -->
<br/>
<br/>
<!-- Return link -->
<p>
<a href="index.html#fig1">Return to article</a>
</p>
<!-- Spacer -->
<br/>
<figure>
<heading alttoc="" refname="fig2" type="figure">Figure 2. netperf on SUT in out of
the box configuration</heading>
<img alt="netperf on SUT in out-of-the-box configuration" height="456" src="figure2_ian.jpg" width="905"/>
</figure>
图1。SUT输入输出上的netserver
盒子的配置
但是,当我在document()函数中硬编码谓词时,我只得到正确的img(如上面的“After”示例所示):
我使用的是oXygen 14.2,我已经用XALAN和SAXON尝试了这个转换,得到了相同的结果
我做错了什么
2013年8月19日更新:
<xsl:variable name="figureRef" select="concat($singleQuote,substring-after(following::a[1]/@href,'#'),$singleQuote)"/>
<xsl:variable name="figureRef"><xsl:value-of select="substring-after(following::a[1]/@href,'#')"/></xsl:variable>
此后,我尝试了另一种方法来获取侧文件中的正确值,但再次没有成功地使document()函数使用其中的变量。与我以前的方法(使用偏移量)一样,当我用一个文本替换document()函数中的变量时,它就工作了
这项工作:
<xsl:copy-of select="document('sidefile.xml',/)/dw-document/dw-sidefile/docbody/figure/img[preceding::heading[1]/@refname = 'fig1']" />
这并不是:
<xsl:copy-of select="document('sidefile.xml',/)/dw-document/dw-sidefile/docbody/figure/img[preceding::heading[1]/@refname = $figureRef]" />
$figureRef变量的定义如下:将指针指向文章文件中的figure元素,抓住figure后面第一个锚点的@href值中“#”后面的字符串;然后,用单引号将其括起来:
<xsl:variable name="figureRef" select="concat($singleQuote,substring-after(following::a[1]/@href,'#'),$singleQuote)"/>
下面是文章文件中的一个xml片段,其中显示了以下元素:
<figure>
<heading alttoc="" refname="fig1" type="figure">Figure 1. netserver on SUT in out of the box configuration</heading>
<img alt="netserver on SUT in out-of-the-box configuration" height="288" src="figure1.jpg" width="572"/>
</figure>
<p><b><a href="http://www.ibm.com/developerworks/library/l-scalability/sidefile.html#fig1">Enlarge Figure 1.</a></b></p>
图1。SUT上的netserver采用开箱即用配置
…我知道figureRef变量正在解析为文章中每个数字的正确值,因为我在document函数之前添加了xsl:comment,以验证其值是否正确:
<xsl:when test="not(image-set)">
<xsl:element name="figure">
<xsl:apply-templates select="heading" />
<xsl:element name="image-set">
<!-- Output the img element that was inside the original figure element -->
<xsl:apply-templates select="img" />
<!-- Output the larger version of the same img that sits in the
sidefile. The "/" as the second argument causes processor to look for the
sidefile in same folder as the article xml file. -->
<xsl:comment>The figureRef is: <xsl:value-of select="$figureRef"/></xsl:comment>
<xsl:copy-of
select="document('sidefile.xml',/)/dw-document/dw-sidefile/docbody/figure/img[preceding::heading[1]/@refname = $figureRef]" />
<xsl:comment>The figureNumber is: <xsl:value-of select="$figureNumber"/></xsl:comment>
</xsl:element>
</xsl:element>
</xsl:when>
图f为:
具体数字如下:
…您可以从下面的结果文档片段中看到它是正确的(在第一个之后应该有另一个img元素):
嘘。下面是一个xml片段,显示了副文件的结构:
<figure>
<heading alttoc="" refname="fig1" type="figure">Figure 1. netserver on SUT in out
of the box configuration</heading>
<image-set>
<img alt="netserver on SUT in out-of-the-box configuration"
height="288" src="figure1.jpg" width="572"/>
<img alt="netserver on SUT in out-of-the-box configuration"
height="456" src="figure1_ian.jpg" width="905"/>
<img alt="netperf on SUT in out-of-the-box configuration"
height="456" src="figure2_ian.jpg" width="905"/>
<img alt="netperf and netserver (bidirectional) on SUT out of the box"
height="456" src="figure3_ian.jpg" width="905"/>
<img alt="netserver, out of the box with numactl"
height="456" src="figure4_ian.jpg" width="905"/>
<img alt="netperf, out of the box with numactl"
height="456" src="figure5_ian.jpg" width="905"/>
<img alt="netperf and netserver (bidirectional), out of the box with numactl"
height="456" src="figure6_ian.jpg" width="905"/>
<img alt="netserver, Ethernet SMP IRQ affinity, no irqbalance"
height="456" src="figure7_ian.jpg" width="905"/>
<img alt="netperf, Ethernet SMP IRQ affinity, no irqbalance"
height="456" src="figure8_ian.jpg" width="905"/>
<img alt="netperf and netserver (bidirectional), Ethernet SMP IRQ affinity, no irqbalance"
height="456" src="figure9_ian.jpg" width="905"/>
<img alt="netserver, Ethernet SMP IRQ affinity and numactl, no irqbalance"
height="456" src="figure10_ian.jpg" width="905"/>
<img alt="netperf, Ethernet SMP IRQ affinity and numactl, no irqbalance"
height="456" src="figure11_ian.jpg" width="905"/>
<img alt="Bidirectional, Ethernet SMP IRQ affinity and numactl, no irqbalance"
height="456" src="figure12_ian.jpg" width="905"/>
<img alt="netserver, Ethernet SMP IRQ affinity, no irqbalance, bonded interfaces"
height="456" src="figure13_ian.jpg" width="905"/>
<img alt="netserver, Ethernet SMP IRQ affinity, no irqbalance, with and without bonding"
height="456" src="figure14_ian.jpg" width="905"/>
<!--The figureNumber is: 1-->
</image-set>
</figure>
<figure>
<heading alttoc="" refname="fig1" type="figure">Figure 1. netserver on SUT in out
of the box configuration</heading>
<img alt="netserver on SUT in out-of-the-box configuration" height="456" src="figure1_ian.jpg" width="905"/>
</figure>
<!-- Spacer -->
<br/>
<br/>
<!-- Return link -->
<p>
<a href="index.html#fig1">Return to article</a>
</p>
<!-- Spacer -->
<br/>
<figure>
<heading alttoc="" refname="fig2" type="figure">Figure 2. netperf on SUT in out of
the box configuration</heading>
<img alt="netperf on SUT in out-of-the-box configuration" height="456" src="figure2_ian.jpg" width="905"/>
</figure>
图1。SUT输入输出上的netserver
盒子的配置
图2。SUT上的netperf输入输出
盒子配置
你做错的第一件事就是试图通过偏移量来链接东西——这是五十年左右众所周知的最简单的链接实现形式,也是最脆弱和最容易出错的。任何事情发生变化时它都会断裂,当它断裂时,它会无声地断裂,这使它变得非常危险。这只是自找麻烦;不要这样做。(看到这里的伤疤了吗?那里的伤疤了吗?我让那些人试着让基于偏移量的链接可靠地工作。从我的悲伤和泪水中学习!)
如果(如您的示例中所示),小图像和大图像具有相同的alt
属性,并且图像文件名是系统相关的,那么您可以通过以下方式获得更好的结果
<xsl:variable name="alt" select="@alt"/>
<xsl:copy-of select="document('side-file.xml',/)
//img[@alt = $alt]"/>
这意味着谓词中的隐式position()将获取图形在其父图形子图形序列中的位置,不是它在文档节点的图形后代中的位置。你做错的第一件事是尝试通过偏移量链接东西——这是50年左右众所周知的最简单的链接实现形式,也是最脆弱和最容易出错的。任何事情发生变化时它都会断裂,当它断裂时,它会无声地断裂,这使它变得非常危险。这只是自找麻烦;不要这样做。(看到这里的伤疤了吗?那里的伤疤了吗?我让那些人试着让基于偏移量的链接可靠地工作。从我的悲伤和泪水中学习!) 如果(如您的示例中所示),小图像和大图像具有相同的
alt
属性,并且图像文件名是系统相关的,那么您可以通过以下方式获得更好的结果
<xsl:variable name="alt" select="@alt"/>
<xsl:copy-of select="document('side-file.xml',/)
//img[@alt = $alt]"/>
这意味着pr中的隐式位置()
<xsl:variable name="figureRef"><xsl:value-of select="substring-after(following::a[1]/@href,'#')"/></xsl:variable>
<xsl:copy-of select="document('sidefile.xml',/)/dw-document/dw-sidefile/docbody/figure/img[preceding::heading[1]/@refname = $figureRef]" />