0
我根据给定元素中的某些属性值拼凑了一个可生成过滤器属性值列表的例程。功能是这样的:尝试在for-each循环内获取父属性值
<xsl:template name="have_arch_attrib">
<!-- We only add a filter attribute IF there is a arch, condition or security attribute-->
<xsl:choose>
<xsl:when test=".[@arch] | .[@condition] | .[@security]">
<xsl:attribute name="filter">
<xsl:for-each select="@arch | @condition | @security ">
<!-- Need to check and convert semis to commas-->
<xsl:variable name="temp_string" select="."/>
<xsl:variable name="rep_string">
<xsl:value-of select="replace($temp_string, ';', ',')"/>
</xsl:variable>
<xsl:value-of select="$rep_string"/>
<!--<xsl:value-of select="." />-->
<xsl:if test="position() != last()">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:attribute>
</xsl:when>
</xsl:choose>
</xsl:template>
但是,对于某些元素,我需要检查该元素的父级属性。所以我重写了这样的:
<xsl:template name="parent_has_arch_attrib">
<!-- We only add a filter attribute IF there is a arch, condition or security attribute-->
<xsl:choose>
<xsl:when test="..[@arch] | ..[@condition] | ..[@security]">
<xsl:attribute name="filter">
<xsl:for-each select="..[@arch] | ..[@condition] | ..[@security] ">
<!-- Need to check and convert semis to commas-->
<xsl:variable name="temp_string" select="."/>
<xsl:variable name="rep_string">
<xsl:value-of select="replace($temp_string, ';', ',')"/>
</xsl:variable>
<xsl:value-of select="$rep_string"/>
<!--<xsl:value-of select="." />-->
<xsl:if test="position() != last()">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:attribute>
</xsl:when>
</xsl:choose>
</xsl:template>
我正在进入这个例程,但没有出来。我认为问题是当我通过select =“。”分配temp_string时。我相信这是现在的因素。如果我尝试select =“..”,它会给我所有的属性值,而不仅仅是for-each循环处理的当前值。我可以在for-each循环中做这样的事吗,还是我必须将它制动?
感谢您的任何帮助!
拉斯
我原以为我应该能够改变for-each语句。 (这是因为初始测试语句确定我们确实有一个具有所需属性的父元素,对吧?) 同样感谢您提供有关减少语句值的提示。 我会给这些尝试,但非常感谢你添! –