xsl-list
[Top] [All Lists]

RE: Need to override previously copied attributes etc.

2005-07-28 16:24:08
Hi thanks for the reply.
When I run that as is, I do not get the desired result, also I don't know
what to do with 
-identity-reference- and -identity-reference-name- if anything?

It basically just copied everything over from the passed in file, but it did
not look to see if an element should get its attributes/nodes from a
referenced element.

Groetjes.

-----Original Message-----
From: Joris Gillis [mailto:roac(_at_)pandora(_dot_)be] 
Sent: Friday, 29 July 2005 1:50 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Need to override previously copied attributes etc.

Hi,
Tempore 02:25:13, die 07/28/2005 AD, hinc in 
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
scripsit Taco Fleur <taco(_at_)shelco(_dot_)com(_dot_)au>:

I have a stylesheet which basically should do the following:
- Copy the whole XML file passed to it
- Apply a template if the element is "field"
      - Copy everything over from the XML file passed
      - Then start copying everything from the XML in a variable
($fieldCollection) where the attribute "identity" matches
              - However if the element from $fieldCollection contains an
attribute 
called "reference" is present it needs to copy everything from the 
element in $fieldCollection that matches that "identity"
              - Then it just needs to copy over that element from
$fieldCollection 
and overwrite any attributes previously copied
              - And finally it needs to copy over the element from the XML
passed 
in and overwrite anything previously there

In Saxon, copied attributes override previously copied attributes.
The following stylesheet gives the desired result:

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

<xsl:output omit-xml-declaration="yes" indent="yes" media-type="string" />

<xsl:variable name="fieldCollection"
select="document('fieldcollection.xml')/root"/>

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

<xsl:template match="field">
<xsl:variable name="match"
select="$fieldCollection/field[current()/@identity = @identity ]"/>
<xsl:copy>
        <xsl:copy-of select="@*" />
        <xsl:apply-templates select="$match" mode="collect_attributes"/>
        <xsl:copy-of select="*"/>
        <xsl:apply-templates select="$match" mode="collect_elements"/>
</xsl:copy> </xsl:template>

<xsl:template match="field" mode="collect_attributes">
        <xsl:param name="exclude">-identity-reference-</xsl:param>
        <xsl:copy-of
select="@*[not(contains($exclude,concat('-',local-name(),'-')))]"/>
        <xsl:apply-templates
select="../field[(_at_)identity=current()/@reference]" 
mode="collect_attributes">
                <xsl:with-param
name="exclude">-identity-reference-name-</xsl:with-param>
        </xsl:apply-templates>
</xsl:template>

<xsl:template match="field" mode="collect_elements">
        <xsl:copy-of select="*"/>
        <xsl:apply-templates
select="../field[(_at_)identity=current()/@reference]" mode="collect_elements"/>
</xsl:template>

</xsl:stylesheet>



regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
Vincit omnia simplicitas
Keep it simple

--~------------------------------------------------------------------
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>
--~--





--~------------------------------------------------------------------
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>
--~--