[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: xsl:copy

Subject: Re: xsl:copy
From: "Agnes Kielen" <a.kielen@xxxxxxx>
Date: Sat, 6 Jul 2002 15:34:11 +0200
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


Current Thread
  • xsl:copy
    • Cenk Uysal - Sat, 6 Jul 2002 08:21:19 -0400 (EDT)
      • Agnes Kielen - Sat, 6 Jul 2002 09:34:30 -0400 (EDT) <=
      • <Possible follow-ups>
      • Marrow - Sat, 6 Jul 2002 09:27:41 -0400 (EDT)

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.