For loop 指定id的每个列表值的XSLT

For loop 指定id的每个列表值的XSLT,for-loop,xslt,each,For Loop,Xslt,Each,我尝试在深层参数中列出值,但仅指定参数。 我对706号的每个测试id执行,当为true时,我对每个和列表值名称执行。我在值之间需要太多分号,但不是在开头和结尾 XML: 这里有一个方法: XSLT1.0 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" i

我尝试在深层参数中列出值,但仅指定参数。 我对706号的每个测试id执行,当为true时,我对每个和列表值名称执行。我在值之间需要太多分号,但不是在开头和结尾

XML:


这里有一个方法:

XSLT1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/parameters">
    <!-- other stuff ? -->
    <sizes3>
        <xsl:for-each select="parameter[@id=706]/value">
            <xsl:value-of select="@name" /> 
            <xsl:if test="position()!=last()">
                <xsl:text>;</xsl:text>
            </xsl:if>
        </xsl:for-each> 
    </sizes3>
    <!-- more stuff ? -->
</xsl:template>

</xsl:stylesheet>

;

更简单、更短、无
、无XSLT条件运算符

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:strip-space elements="*"/>

  <xsl:template match="/">
    <size3><xsl:apply-templates/></size3>
  </xsl:template>

  <xsl:template match="parameter[@id=706]/value">
   <xsl:apply-templates select="@name"/>
  </xsl:template>

  <xsl:template match="parameter[@id=706]/value[position() > 1]" priority="2">
    <xsl:text>;</xsl:text><xsl:apply-templates select="@name"/>
  </xsl:template>
</xsl:stylesheet>

;
<sizes3>jasny róż; 97% bawełna, 3% poliamid;46; ona;</sizes3>
<sizes3>46;47;48</sizes3>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/parameters">
    <!-- other stuff ? -->
    <sizes3>
        <xsl:for-each select="parameter[@id=706]/value">
            <xsl:value-of select="@name" /> 
            <xsl:if test="position()!=last()">
                <xsl:text>;</xsl:text>
            </xsl:if>
        </xsl:for-each> 
    </sizes3>
    <!-- more stuff ? -->
</xsl:template>

</xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:strip-space elements="*"/>

  <xsl:template match="/">
    <size3><xsl:apply-templates/></size3>
  </xsl:template>

  <xsl:template match="parameter[@id=706]/value">
   <xsl:apply-templates select="@name"/>
  </xsl:template>

  <xsl:template match="parameter[@id=706]/value[position() > 1]" priority="2">
    <xsl:text>;</xsl:text><xsl:apply-templates select="@name"/>
  </xsl:template>
</xsl:stylesheet>