xsl-list
[Top] [All Lists]

RE: [xsl] copying a node

2006-03-07 17:41:35
lists(_at_)bitfaeule(_dot_)net wrote:

<?xml version="1.0" encoding="utf-16" ?>
<filter name="ARMCheckTest">
      <group section="mini">
      </group>
      <group section="basic">
              <test name="testCheck1"></test>
              <test name="testCheck2"></test>
      </group>
</filter>

... needs to be transformed into

<?xml version="1.0" encoding="utf-16" ?>
<filter name="ARMCheckTest">
      <group section="mini">
      </group>
      <group section="basic">
              <test name="testCheck1"></test>
              <test name="testCheck2"></test>
      </group>

      <group section="basic-alt">
              <test name="testCheck1"></test>
              <test name="testCheck2"></test>
      </group>
</filter>

That is the node "group" with the attribute section="basic" needs to
be duplicated and the value for section must be modified. 

I can think of a couple of implementations using xsl:foreach or
xsl:if but I'm sure I would come up with something alittle too
complicated. What's the easiest implemetation to do this?

  I think about a Modified Identity Transformation:

    <xsl:stylesheet
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
        version="1.0">

      <xsl:output indent="yes"/>

      <xsl:template match="@*|node()">
        <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
      </xsl:template>

      <xsl:template match="group[(_at_)section='basic']">
        <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
        <xsl:copy>
          <xsl:attribute name="section">basic-alt</xsl:attribute>
          <xsl:apply-templates
              select="@*[local-name()!='section']|node()"/>
        </xsl:copy>
      </xsl:template>

    </xsl:stylesheet>

  Regards,

--drkm




















        

        
                
___________________________________________________________________________ 
Nouveau : téléphonez moins cher avec Yahoo! Messenger ! Découvez les tarifs 
exceptionnels pour appeler la France et l'international.
Téléchargez sur http://fr.messenger.yahoo.com

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>