Xslt 如何在for each循环中选择前面的同级?
我的XMLXslt 如何在for each循环中选择前面的同级?,xslt,xslt-1.0,Xslt,Xslt 1.0,我的XML 伯莱斯克帝国1 帝国滑稽剧2 帝国滑稽剧2 XSL 前面的同级不打印任何内容。我想将两者存储在不同的变量中,并对它们进行比较。您能帮我指出这里有什么问题吗?当前,当您检查前面的元素时,您位于cd元素上,并且只有其他cd元素作为同级元素。因此,您需要的表达式是: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/19
伯莱斯克帝国1
帝国滑稽剧2
帝国滑稽剧2
XSL
前面的同级不打印任何内容。我想将两者存储在不同的变量中,并对它们进行比较。您能帮我指出这里有什么问题吗?当前,当您检查前面的元素时,您位于
cd
元素上,并且只有其他cd
元素作为同级元素。因此,您需要的表达式是:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="catalog/cd">
<xsl:call-template name="currentValue" />
<xsl:call-template name="prevValue" />
</xsl:for-each>
</xsl:template>
<xsl:template name="currentValue">
<xsl:value-of select="title/name" />
</xsl:template>
<xsl:template name="prevValue">
<xsl:value-of select="preceding-sibling::title[name][1]" />
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="catalog/cd">
<xsl:call-template name="currentValue" />
<xsl:call-template name="prevValue" />
</xsl:for-each>
</xsl:template>
<xsl:template name="currentValue">
<xsl:value-of select="title/name" />
</xsl:template>
<xsl:template name="prevValue">
<xsl:value-of select="preceding-sibling::title[name][1]" />
</xsl:template>
</xsl:stylesheet>
<xsl:value-of select="preceding-sibling::cd[1]/title/name" />