Search

I have a XML 100120014001102202234383163

I would like to use xsl to parse into another XML. The output would be

<comp value="100,200,400|10,20|2,4,8,16"/> 

where the componentsids belonged to different groupid are separated by "|" . The component_sids belonged to the same group id should be concatenated with ",". I used the following xsl

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
    <xsl:element name="comp">
    <xsl:attribute name="value">
     <xsl:call-template name="join"> 
    <xsl:with-param name="list" select="//DATA_RECORD[GROUP_ID=1]/COMPONENT_SID" /> 
        <xsl:with-param name="separator" select="','" />                     
    </xsl:call-template> 
      </xsl:attribute>
    </xsl:element>
  </xsl:template>

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

The result is

<comp value="100,200,400"/>

. But I could not figure out how to separate other groups of component_sid with "|". Can someone help me?

Thanks in advance

Can you show us what you've tried so far? What are the results/errors you're seeing?

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details