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

RE: Moving an element to a new location in the Result

Subject: RE: Moving an element to a new location in the Result-tree
From: "Graves, Jim \(CONTR\)" <jim.graves@xxxxxxx>
Date: Wed, 7 Sep 2005 18:27:34 -0700
jim graves
Chris,

Good ideas! More details to get closer to a solution. It's copying and
maintaining the tree as it is, yet still not 'moving' (figuratively, not
literally, since it's a new tree) the elements to the new location in
the new (result) tree. I think I see your logic, but I'm still missing a
crucial insight. Can you pinpoint what it is -- to see the result
desired, below?

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform version="1.0"

<xsl:template  match="/">
	<xsl:apply-templates/>
</xsl:template>

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="Transfer">
    <xsl:apply-templates select="Person"/>
</xsl:template>


<xsl:template match="Person">
     <xsl:apply-templates select="*[not(self::OTHER_NAME)]"/>
     <xsl:apply-templates select="OTHER_NAME"/>
</xsl:template>


</xsl:transform >


Example data looks like:
<Transfer>
<Person>
<PDQ:NAME_LAST>PEITER</PDQ:NAME_LAST>
<PDQ:NAME_FIRST>REED</PDQ:NAME_FIRST>
<PDQ:NAME_MIDDLE>NAMESCO</PDQ:NAME_MIDDLE>

<OTHER_NAME>
<xyz:OTHER_NAME_TYPE>UNKNOWN</xyz:OTHER_NAME_TYPE>
<ABC:Name>DA STEAFANO, ANNEX</ABC:Name>
</OTHER_NAME>

<OTHER_NAME>
<xyz:OTHER_NAME_TYPE>UNKNOWN</xyz:OTHER_NAME_TYPE>
<ABC:Name>PURSA, BILL, SR</ABC:Name>
</OTHER_NAME>

<PDQ:BIRTH_DATE>19510516</PDQ:BIRTH_DATE>
<PDQ:GENDER>M</PDQ:GENDER>
<xyz:IND_HEIGHT>67"  </xyz:IND_HEIGHT>
<xyz:IND_WEIGHT>150</xyz:IND_WEIGHT>
<xyz:EYE_COLOR>Brown</xyz:EYE_COLOR>
<xyz:HAIR_COLOR>Brown</xyz:HAIR_COLOR>
</Person>
</Transfer>

Should look like:

<Transfer>
<Person>
<PDQ:NAME_LAST>PEITER</PDQ:NAME_LAST>
<PDQ:NAME_FIRST>REED</PDQ:NAME_FIRST>
<PDQ:NAME_MIDDLE>NAMESCO</PDQ:NAME_MIDDLE>
<PDQ:BIRTH_DATE>19510516</PDQ:BIRTH_DATE>
<PDQ:GENDER>M</PDQ:GENDER>
<xyz:IND_HEIGHT>67"  </xyz:IND_HEIGHT>
<xyz:IND_WEIGHT>150</xyz:IND_WEIGHT>
<xyz:EYE_COLOR>Brown</xyz:EYE_COLOR>
<xyz:HAIR_COLOR>Brown</xyz:HAIR_COLOR>

<OTHER_NAME>
<xyz:OTHER_NAME_TYPE>UNKNOWN</xyz:OTHER_NAME_TYPE>
<ABC:Name>DA STEAFANO, ANNEX</ABC:Name>
</OTHER_NAME>

<OTHER_NAME>
<xyz:OTHER_NAME_TYPE>UNKNOWN</xyz:OTHER_NAME_TYPE>
<ABC:Name>PURSA, BILL, SR</ABC:Name>
</OTHER_NAME>

</Person>
</Transfer>

That's still a stretch for me really -- should this adaptation of your
approach be tweaked in some way?

Thanks,
Jim

-----Original Message-----
From: Christopher R. Maden [mailto:crism@xxxxxxxxx]
Sent: Wednesday, 07 September 2005 17:39
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  Moving an element to a new location in the
Result-tree

Jim Graves writes:
> Yes, I'm probably am thinking in a procedural manner, more than
> 50%/time.
> Please let me clarify my problem with more details:
>
> Let's suppose my source document looks like this: (note: repeating
"b1"
> elements)
>
> I want to move the former "b1" elements down the tree and re-name them
> (all) along the way,

Here is the key.  You aren't moving or renaming anything.

You are creating an entirely new document.  It may or may not bear any
resemblance to the input document.

Think in those terms, and you will achieve victory! (-:

Here's a transformation.  It's just the identity transform, but the
children of document1 aren't processed in document order.

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

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="document1">
  <document222>
    <xsl:apply-templates select="*[not(self::b1)]"/>
    <xsl:apply-templates select="b1"/>
  </document222>
</xsl:template>

</xsl:transform>

~Chris
--
Christopher R. Maden, Principal Consultant, crism consulting
XML-SGML-HTML-DTDs-schemas-XSL-DSSSL-conversion-training-ebooks-B2B
<URL: http://crism.maden.org/consulting/ >
PGP Fingerprint: BBA6 4085 DED0 E176 D6D4  5DFC AC52 F825 AFEC 58DA

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.