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

Re: Creating elements in an arbitrary position in the

Subject: Re: Creating elements in an arbitrary position in the result document
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Sun, 17 Jan 2010 20:19:11 -0500
Re:  Creating elements in an arbitrary position in the
At 2010-01-18 01:48 +0100, cvergara@xxxxxxxxxxxxxxxxxx wrote:
Hello,

using the information in a subtree of a source document, I would like to
create an element in an arbitrary position in the result document:
Source:
<?xml version="1.0"?>
<A>
... <- unknown/variable amount of nodes
  <B>
    <C attrC="value1"/>
      <D attrD="value2"/>
  </B>
</A>
Result:
<A>
  <new_element attrC="value1" attrD="value2"/>
    ... <- unknown amount of elements in source between A and B
    <B>
...

Is it possible to do this? I didn't find it in the FAQ of things that are
not possible in XSLT.
If yes, how?

It looks like all you are doing is starting the reconstituted A with a new first child and then processing the original content as is.


An example is below, but I'm guessing I'm missing something from your description. Your behaviour for <B> would be added to my solution with a template matching it. BTW, I know you don't have attributes for <A> but I left handling for that in the solution.

I hope this helps.

. . . . . . . . . . Ken

t:\ftemp>type cristobal.xml
<A>
... &lt;- unknown/variable amount of nodes
  <B>
    <C attrC="value1"/>
      <D attrD="value2"/>
  </B>
</A>

t:\ftemp>xslt cristobal.xml cristobal.xsl
<?xml version="1.0" encoding="utf-8"?><A><new_element attrC="value1" attrD="valu
e2"/>
... &lt;- unknown/variable amount of nodes
<B>
<C attrC="value1"/>
<D attrD="value2"/>
</B>
</A>
t:\ftemp>type cristobal.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">


<xsl:template match="A">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <new_element attrC="value1" attrD="value2"/>
    <xsl:apply-templates select="node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="@*|node()"><!--identity for all other nodes-->
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>

t:\ftemp>


-- UBL and Code List training: Copenhagen, Denmark 2010-02-08/10 XSLT/XQuery/XPath training after http://XMLPrague.cz 2010-03-15/19 XSLT/XQuery/XPath training: San Carlos, California 2010-04-26/30 Vote for your XML training: http://www.CraneSoftwrights.com/s/i/ Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal

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.