This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: xsl:copy


Hi,

Cenk wrote:

> I have a XSL file as follows:
>
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
>   <xsl:template match="/ | @* | node()">
>     <xsl:copy>
>       <xsl:apply-templates select="@* | node()"/>
>     </xsl:copy>
>   </xsl:template>
> </xsl:stylesheet>

>I try to copy a XML file's tags which satisifies my
> language filtering. For example I will only copy following XML's
> lang='en' and no language defined tags:
>
> <page>
> <title lang="tr">Hoºgeldiniz</title>
> <title lang="en">Wellcome</title>
> <description>
>   assafs aszdfsd
> </description>
> </page>

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

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

  <xsl:template match="node()">
 <xsl:copy>
    <xsl:apply-templates select="node()[@lang='en'] | node()[not(@lang)]"
mode="cp"/>
     </xsl:copy>
  </xsl:template>

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

I split the <xsl:template match="/ | @* | node()"> in two seperate
templates. I removed match / because that is not really necessary. By the
"match=node()" the copy is only done when the @lang is 'en' or does not
exist. In that case the template with mode='cp' is called.

Hope that helps,
Agnes



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]