[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Merging multiple documents and combining the resul
Never mind. I figured out the issue. When I changed select="document(/files/file)/notification/components/component"/> to select="document(/files/file)//component"/>, the transformation worked. Thanks, Mark On Nov 2, 2007 9:11 AM, Mark Peters <flickrmeister@xxxxxxxxx> wrote: > Hi Everyone, > > I have several files that I'm trying to merge into a single document. > In the examples below, I'm trying to combine the component nodes based > on the id attribute of the name sub-node. > > File 1: > > <?xml version="1.0" encoding="UTF-8"?> > <notification> > <components> > <component> > <name id="cpobj1">Fish</name> > <mode>Swims</name> > </component> > <component> > <name id="cpobj35">Giraffe</name> > <mode>Walks</name> > </component> > </components> > </notification> > > File 2: > > <?xml version="1.0" encoding="UTF-8"?> > <notification> > <components> > <component> > <name id="cpobj1">Fish</name> > <skin>Scales</skin> > </component> > <component> > <name id="cpobj45">Ball</name> > <shape>Round</shape> > </component> > </components> > </notification> > > File 2: > > <?xml version="1.0" encoding="UTF-8"?> > <notification> > <components> > <component> > <name id="cpobj3">Bird</name> > <mode>Flies</name> > </component> > <component> > <name id="cpobj45">Ball</name> > <mode>Rolls</name> > </component> > </components> > </notification> > > > My output would resemble the following: > > > <?xml version="1.0" encoding="UTF-8"?> > <notification> > <components> > <component> > <name id="cpobj1">Fish</name> > <mode>Swims</name> > <skin>Scales</skin> > </component> > <component> > <name id="cpobj35">Giraffe</name> > <mode>Walks</name> > </component> > <component> > <name id="cpobj45">Ball</name> > <shape>Round</shape> > <mode>Rolls</name> > </component> > <component> > <name id="cpobj3">Bird</name> > <mode>Flies</name> > </component> > </components> > </notification> > > > I used the following transformation: > > > <xsl:stylesheet version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:exslt="http://exslt.org/common"> > <xsl:output indent="yes"/> > <xsl:template match="/"> > <xsl:variable name="temp"> > <components> > <xsl:copy-of > select="document(/files/file)/notification/components/component"/> > </components> > </xsl:variable> > <notification> > <components> > <xsl:for-each > select="exslt:node-set($temp)/components/component[generate-id()=generate-id(key('c',name/@id))]"> > <xsl:sort select="name/@id"/> > <xsl:copy> > <xsl:copy-of select="@*|key('c',name/@id)/*"/> > </xsl:copy> > </xsl:for-each> > </components> > </notification> > </xsl:template> > <xsl:key name="c" match="component" use="name/@id"/> > </xsl:stylesheet> > > > The output doesn't combine the component nodes by /name/@id. Each > component is treated as a separate node, with no relationship with any > other node. > > <?xml version="1.0" encoding="UTF-8"?> > <notification xmlns:exslt="http://exslt.org/common"> > <components> > <component> > <name id="cpobj1">Fish</name> > <mode>Swims</name> > </component> > <component> > <name id="cpobj35">Giraffe</name> > <mode>Walks</name> > </component> > <component> > <name id="cpobj1">Fish</name> > <skin>Scales</skin> > </component> > <component> > <name id="cpobj45">Ball</name> > <shape>Round</shape> > </component> > <component> > <name id="cpobj3">Bird</name> > <mode>Flies</name> > </component> > <component> > <name id="cpobj45">Ball</name> > <mode>Rolls</name> > </component> > </components> > </notification> > > Does anyone know how I could combine the component nodes based on the > name/@id value? > > Thanks, > Mark > > > -- > > Mark Peters > Senior Technical Writer > Saba Software > -- Mark Peters Senior Technical Writer Saba Software
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|