在 XSLT 中将元素循环到单个元素 [英] Looping Element to Single Element in XSLT

查看:19
本文介绍了在 XSLT 中将元素循环到单个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要转换以下内容

    <QTLS_ITEM>
      <ID>123</ID>
      <ID1>1345</ID1>
      <SERAIL_NUMBER>1026977­04257</SERAIL_NUMBER>
     <PROD_NAME>upgrade</PROD_NAME>
    </QTLS_ITEM>
    <QTLS_ITEM>
      <ID>123</ID>
      <ID1>1345</ID1>
      <SERAIL_NUMBER>1026977­04257</SERAIL_NUMBER>
      <PROD_NAME>Plug­in</PROD_NAME>
    </QTLS_ITEM>
    <QTLS_ITEM>
      <ID>123</ID>
      <ID1>1345</ID1>
      <SERAIL_NUMBER>1026977­04257</SERAIL_NUMBER>
      <PROD_NAME>License</PROD_NAME>
    </QTLS_ITEM>

这是一个循环元素类型. 是一个重复元素.对于每个元素,我必须连接这两个字段并获得如下值.
我想把它转换成一个像

This is a looping element type.<QTLS_ITEM> is a repeating element. For each element I have to concatenate those two fields and get the value as below.
I want to transform it into a single Element like

<Item_description>
1026977­04257 upgrade
1026977­04257 Plug­in
1026977­04257 License
<Item_Description>

这意味着我需要连接 SERAIL_NUMBERPROD_NAME.
有人可以帮忙吗?

Which means I need to concatenate both the SERAIL_NUMBER and PROD_NAME.
Can anyone help on this?

<xsl:template name="string-join">
  <xsl:param name="nodes"/>
  <xsl:param name="delimiter"/>
  <xsl:for-each select="$nodes">
    <xsl:value-of select="."/>
    <xsl:if test="$nodes[position()!=last()-1]">
      <xsl:value-of select="$delimiter"/>
    </xsl:if>
  </xsl:for-each>
</xsl:template>

我正在使用它来获取以逗号分隔的序列号.但我想连接并得到上述格式的结果.

I am using this to get the Serial numbers separated by comma. But I want to concatenate and get the result in the above format.

我的情况的答案是

<xsl:template name="join">
    <xsl:param name="list"/>
    <xsl:param name="separator"/>
    <xsl:for-each select="db:SERAIL_NUMBER | db:PROD_NAME">($list value)
      <xsl:value-of select="."/>
      <xsl:if test="position() != last()">
        <xsl:value-of select="$separator"/>
      </xsl:if>
    </xsl:for-each>
  </xsl:template> 

推荐答案

这对我来说已经解决了

<xsl:template name="join">
    <xsl:param name="list"/>
    <xsl:param name="separator"/>
    <xsl:for-each select="db:SERAIL_NUMBER|db:PROD_NAME">($list value)
      <xsl:value-of select="."/>
      <xsl:if test="position() != last()">
        <xsl:value-of select="$separator"/>
      </xsl:if>
    </xsl:for-each>
  </xsl:template> 

这篇关于在 XSLT 中将元素循环到单个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆