【问题标题】:map multiple input element to a single output response element as comma separated以逗号分隔将多个输入元素映射到单个输出响应元素
【发布时间】:2016-03-25 06:19:33
【问题描述】:

我正在尝试将 XSD 中处于同一级别的多个输入作为逗号分隔值映射到目标元素。这在 XSLT 1.0 中是否可行

输入结构

<Errors>
<error>
<errorcode>code</errorcode>
<errortype>type</errortype>
<paramater1>error1</paramater1>
<paramater2>error2</paramater2>
<paramater3/>error3</paramater3>
<paramater4/>error4</paramater4>
<error>
<Errors>

输出

<output>error1,error2,error3,error4</output>

请注意 - 错误代码、错误类型等其他元素应保持不变。我在其他映射中使用这些元素。

【问题讨论】:

    标签: xslt xslt-1.0


    【解决方案1】:

    您可以尝试使用这些模板:

    <xsl:template match="error">
        <xsl:copy>
            <!-- apply identity transform for child elements which name doesn't start with 'parameter' -->
            <xsl:apply-templates select="*[not(starts-with(name(), 'paramater'))]"/>
    
            <!-- output comma-separated value from child elements which name start with 'parameter' -->
            <output>
                <xsl:for-each select="*[starts-with(name(), 'paramater')]">
                    <xsl:value-of select="."/>
                    <xsl:if test="position() &lt; last()">
                        <xsl:text>,</xsl:text>
                    </xsl:if>
                </xsl:for-each>
            </output>
        </xsl:copy>
    </xsl:template>
    
    <!-- identity template -->
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-20
      • 1970-01-01
      • 1970-01-01
      • 2022-12-15
      • 1970-01-01
      相关资源
      最近更新 更多