我有一个关于 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”结果,就好像没有索引一样。我可以看到我错过了 postion() 周围的 {},但如果我添加它们,我会得到这个 xsl 错误:Invalid XPath expression Unexpected token - "{position()}]/foto-dida" select="/doc/articolo/照片组[{position()}]/foto-dida"
有谁知道我想念什么或我应该改变什么?非常感谢