[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re:XML Merge
>From: David Carlisle <davidc@xxxxxxxxx> >Subject: Re: Re: XSL-List Digest V4 #1421 >I've changed that to the following now: ><xsl:when test="action"> > <xsl:apply-templates select="action"/> ></xsl:when> > > >unless you also moved the xsl:copy outside that is still going to give >you the problem that parents of action elements are not copied. >I don'tthink you want the xsl:choose at all. Since that last post, I've made some slight modifications, and I'm closer to what I'm trying to accomplish. All parents are being copied as far as I can tell (at least they appear to be when I'm stepping through the transformation with XML Spy 5's debugger). Here is the latest style sheet: <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml"/> <xsl:template match="/"> <xsl:apply-templates /> </xsl:template> <xsl:template match="*|@*|comment()|processing-instruction()|text()"> <xsl:choose> <xsl:when test="action-mappings/action"> <xsl:apply-templates select="action-mappings/action"/> </xsl:when> <xsl:otherwise> <xsl:copy> <xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()"/> </xsl:copy> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="action-mappings/action"> <xsl:choose> <xsl:when test="@path = document('struts-config_new_variables01.xml')//action/@path"> <!-- Copy the value where @path = document()//action/@path --> <xsl:variable name="pathvalue" select="@path"/> <xsl:variable name="nodeset" select="document('struts-config_new_variables01.xml')//action[@path = $pathvalue]"/> <!-- <xsl:copy-of select="document('struts-config_new_variables01.xml')//action[@path = $pathvalue]"/> --> <xsl:element name="action"> <xsl:apply-templates select="$nodeset/@*"/> <xsl:apply-templates select="$nodeset/forward"/> <xsl:apply-templates select="* | @* | comment() | processing-instruction() | text()"/> </xsl:element> </xsl:when> <xsl:otherwise> <xsl:copy> <xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()"/> </xsl:copy> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="action/forward"> <xsl:copy> <xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()"/> </xsl:copy> </xsl:template> </xsl:stylesheet> The only problem I'm running into and need to fix is that if an action element has two child forward elements in the external xml file, and the action element in the main xml file has the same two child elements, both the forward elements and all the forward elements from the main xml file are being copied. i.e. if I have something like this: external xml file: <action> <forward path="1" step="0"/> <forward path="2" step="2"/> </action> main xml file: <action> <forward path="1" step="1"/> <forward path="2" step="2"/> <forward path="3" step="2"/> </action> result file: <action> <forward path="1" step="0"/> <forward path="2" step="2"/> <forward path="1" step="1"/> <forward path="2" step="2"/> <forward path="3" step="2"/> </action> What I want is the following output: <action> <forward path="1" step="0"/> <forward path="2" step="2"/> <forward path="3" step="2"/> </action> ===== "The difference between fiction and reality is that fiction has to make sense." - Tom Clancy XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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
|