我有一个关于xsl语法的问题:这是我的xsl:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:html="http://www.w3.org/Profiles/XHTML-transitional" exclude-result-prefixes="html">
<xsl:output method="xml" omit-xml-declaration="yes" indent="no" encoding="utf-8" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" />
<xsl:param name="objectDoc" />
<xsl:template match="/">
<xsl:for-each select="/articolo/foto-group/fg-foto">
<div class="Image_container">
<div class="EM_Story_Image_{position()}"></div>
</div>
<div class="Caption"><xsl:value-of select="/articolo/foto-group[position()]/foto-dida"/></div>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>下面是我的xml:
<articolo>
<foto-group id="U50253517593AED">
<fg-foto id="kYjG"/>
<foto-dida class="dida" id="kSo">
<p>Heloooooooooooo </p>
</foto-dida>
</foto-group>
<foto-group id="U50253517593c0E">
<fg-foto id="kNTF"/>
</foto-group>
<foto-group id="U50253517593h4B">
<fg-foto id="kRtH"/>
</foto-group>
</articolo>我所拥有的是这个xml:
<!DOCTYPE div PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<div class="Image_container">
<div class="EM_Story_Image_1"/></div>
<div class="Caption">Heloooooooo</div>
<div class="Image_container">
<div class="EM_Story_Image_2"/></div>
<div class="Caption">Heloooooooo </div>
<div class="Image_container">
<div class="EM_Story_Image_3"/></div>
<div class="Caption">Heloooooooo </div>但我期望的是:
<!DOCTYPE div PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<div class="Image_container">
<div class="EM_Story_Image_1"/></div>
<div class="Caption">Heloooooooo</div>
<div class="Image_container">
<div class="EM_Story_Image_2"/></div>
<div class="Caption"> </div>
<div class="Image_container">
<div class="EM_Story_Image_3"/></div>
<div class="Caption"> </div>所以基本上不能正常工作的指令是这样的:
<xsl:value-of select="/articolo/foto-group[position()]/foto-dida"/>因为我期望的是一个数字(1,2,3),而不是位置。
<div class="EM_Story_Image_{position()}"></div>相反,我总是从它获得节点一"Helooooooo“的结果,就好像没有索引一样。我可以看到我错过了position()周围的{},但是如果我添加它们,我会得到这个xsl错误:无效的位置表达式意外标记-“{ XPath ()}]/foto-dida”select="/doc/articolo/foto-group{position()}/foto-dida“
有人知道我错过了什么或者我应该改变什么吗?非常感谢
发布于 2012-11-15 03:17:11
在您的select中,没有理由从root开始。上下文已经是fg-foto,所以只获取其父上下文的foto-dida子级。您应该将xsl:value-of更改为:
<xsl:value-of select="../foto-dida/p"/>发布于 2012-11-15 03:24:14
在计算该<xsl:value-of>时,当前上下文节点是一个fg-foto元素,因此
<xsl:value-of select="../foto-dida" />应该会给出同级foto-dida元素的字符串值。
发布于 2012-11-15 03:27:23
而不是
<xsl:value-of select="/articolo/foto-group[position()]/foto-dida"/>尝尝这个
<xsl:value-of select="current()/foto-dida"/>https://stackoverflow.com/questions/13385412
复制相似问题