Subject: xsl:apply-templates - Pls help me out imme
Posted By: Avinash Post Date: 11/13/2003 12:04:05 AM
Dear all
    Please help me imme in solving this.
I have some thing like this -
<tag1>
    ........
    ........
    <childtag1>ChildValue1</childtag1>
    <childtag1>ChildValue2</childtag1>
    <childtag1>ChildValue3</childtag1>
    .......
</tag1>

In the XSL, Iam using
    <xsl:template match='tag1'>
        <test1><xsl:apply-templates select="childtag1"></test1>
    </xsl:template>

The <xsl:apply-templates> element applies a template rule to the current

element or to the current element's child nodes.
So the output value (in the output xml) Iam getting is -
    <test1>ChildValue1ChildValue2ChildValue3</test1>
I want this output to be separated by commas, like
    <test1>ChildValue1, ChildValue2, ChildValue3</test1>.

How to achieve this?
Thx in advance.

-Avinash


***********************************

Reply By: armmarti Reply Date: 11/13/2003 2:18:19 AM
Hi,

I can suggest 2 approaches.

1) Add template rule for "childtag1":

<xsl:template match="childtag1">
 <xsl:value-of select="."/>
 <xsl:if test="following-sibling::childtag1">
  <xsl:text>,</xsl:text>
 </xsl:if>
</xsl:template>

2) or change the code you posted like this:

<xsl:template match='tag1'>
 <test1>
  <xsl:for-each select="childtag1">
    <xsl:value-of select="."/>
    <xsl:if test="position() != last()">
     <xsl:text>,</xsl:text>
    </xsl:if>
  </xsl:for-each>
 </test1>
</xsl:template>


Just for this example the second is more intuitive and readable and finally faster I think.

Regards,
Armen

Go to topic 6347

Return to index page 1006
Return to index page 1005
Return to index page 1004
Return to index page 1003
Return to index page 1002
Return to index page 1001
Return to index page 1000
Return to index page 999
Return to index page 998
Return to index page 997