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

Re: Copying an entire NodeSet with modified selected

Subject: Re: Copying an entire NodeSet with modified selected attribute values
From: Klaus Berger <klberger@xxxxxxxxx>
Date: Thu, 23 Jun 2005 17:50:04 +0200
svg copy node
2005/6/23, michella@xxxxxxx <michella@xxxxxxx>:
> Hi all,
>
> A need a little help :
>
> Given SVG:
>
> <svg width="100%" height="100%" viewBox="-24 -21 1296 1135"
> preserveAspectRatio="xMinYMin meet" kerning="0" xml:space="preserve"
> xmlns:xlink="http://www.w3.org/1999/xlink" style="stroke: black; fill:
> none;">
>        <g id="122" type="443" node="Yes">
>        ...
>        </g>
> </svg>
>
> I would like to keep/copy the entire SVG Structure, but just change
> specific attribute values.
>
> Example :clone it, except that : (...) height="NEWVALUE" (...)
>
> Could it be possible to simple use xsl:copy-of function with exceptions
> (IFs)?
>

I would suggest the following steps

1. Copy the element node
2. Copy all attributes
3. Replace existing attributes or add new ones
4. Copy child nodes or apply templates to child nodes

<xsl:template match="svg">
    <!--  copy element node svg  -->
    <xsl:copy>

        <!--  copy all attributes -->
        <xsl:copy-of select="@*"/>

        <!--  xsl:attribute will replace any attribute copied by above
instruction -->
        <xsl:attribute name="height"><!--  new value --></xsl:attribute>
        ...
        <!--  copy child nodes ... -->
        <xsl:copy-of select="node()"/>

        <!--  ... or apply templates to child nodes  -->
        <xsl:apply-templates/>

    </xsl:copy>
</xsl:template>

Note, however, that you cannot remove attributes this way,
only replace existing ones or add new ones.

If you want to remove attributes, you have to filter the attribute
select expression like

<xsl:copy-of select="@*[not(name()='height') and not(...)...]"/>

Regards - Klaus

> Thanks for your replies ;-)
>
> Lawrence Michel

Current Thread

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.