OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] Rebuild XML file and merge

[ Lists Home | Date Index | Thread Index ]

Hi Taco,

You need to pull out your fields in the "field" template and use
for-each instead of just copy-of. Copy-of is a pretty dumb construct,
when what you need is some control over what you're copying.

Instead, where you've got ;

          <xsl:if test="name() = 'field'"> <testing /> </xsl:if>

replace it with an xsl:choose, xsl:when and xsl:otherwise (on the same
test as your original), and when you want to include or overwrite
attributes, add your selection ($fieldCollection/field[
current()/@identity = @identity ]/@*) to the <xsl:for-each
select="@*">. (Or, if you're a bit fancier, just create variables with
your selections and constructs, and copy over "anything" you've found
in a loop :)

Anyways, if you'd also give a sample of your input XML and your
expected result we could help a little better.


Alex



On 7/22/05, Taco Fleur <taco@shelco.com.au> wrote:
>  
>  
> 
> Hi all.. 
> 
>   
> 
> I am trying to rebuild an XML file and merge it, I am having some difficulty
> getting the XSL right. 
> 
>   
> 
> I need to maintain the structure of the original XML file I feed to this
> transformation, but when I come to the element "field" I need to merge the
> elements from the $fieldCollection variable and have any attributes
> overwritten in the original file by $fieldcollection. Below is what I have
> been able to pull together, but obviously its not working. Any help is very
> much appreciated. 
> 
>   
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
>  <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('C:\Inetpub\wwwroot\development\shelco_company_registration_form\xml\field.xml')/root"/>
>  
>       <xsl:template match="/">
>            <xsl:apply-templates />
>       </xsl:template>
>  
>       <xsl:template match="*">
>            <xsl:if test="name() = 'field'">
>                 <testing />
>                      <xsl:apply-templates ***** call the field template!!
> ***** />
>            </xsl:if>
>            <xsl:element name="{name()}">
>                 <xsl:for-each select="@*">
>                      <xsl:attribute name="{name()}">
>                           <xsl:value-of select="."/>
>                      </xsl:attribute>
>                 </xsl:for-each>
>                 <xsl:apply-templates />
>            </xsl:element>
>       </xsl:template>
>  
>       <xsl:template match="field">
>                 <xsl:copy>
>                      <xsl:copy-of select="@*" />
>                      <xsl:copy-of select="$fieldCollection/field[
> current()/@identity = @identity ]/@*" />
>                      <xsl:element name="$fieldCollection/field[
> current()/@identity = @identity ]/*">
>                           <xsl:copy-of select="$fieldCollection/field[
> current()/@identity = @identity ]/*" />
>                      </xsl:element>
>                 </xsl:copy>
>       </xsl:template>
>  
>  </xsl:stylesheet> 
> 
>   
> 
> ________________________________ 
> 
> Taco Fleur - E-commerce Development Manager 
> 
> Shelco Searches & Services 
> 
> An Authorised ASIC Information Broker 
> 
> www.shelco.com.au 
> 
> Ph: + 61 7 3236 2605 
> 
>   


-- 
"Ultimately, all things are known because you want to believe you know."
                                                         - Frank Herbert
__ http://shelter.nu/ __________________________________________________




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS