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

RE: Noobie: normalize <b><a>...</a></b> to <a><b>...<

Subject: RE: Noobie: normalize <b><a>...</a></b> to <a><b>...</b></a>
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 18 Feb 2010 18:09:30 -0000
RE:  Noobie: normalize <b><a>...</a></b> to  <a><b>...<
Two templates: an identity template that copies everything by default

<xsl:template match="*">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
  </
</

and a template for the nodes you want to change:

<xsl:template match="b[a][count(child::node()=1]">
  <a>
    <b>
      <xsl:apply-templates select="a/child::node()"/>
    </b>
  </a>
</xsl:template>

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 
 

> -----Original Message-----
> From: Kenneth Reid Beesley [mailto:krbeesley@xxxxxxxxx] 
> Sent: 18 February 2010 17:55
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Noobie: normalize <b><a>...</a></b> to 
> <a><b>...</b></a>
> 
> 
> I'm converting a non-XML data-dump into XML, and the document 
> contains examples of both
> 
> <a><b>...</b></a>
> 
> and
> 
> <b><a>...</a></b>
> 
> which (in this document) are equivalent.  I'd like to use 
> XSLT to convert all examples of the latter to the former, 
> with the following
> caveats:
> 
> 1.  <b> can contain mixed text, in which case nothing should 
> be changed.
> 2.  <b><a>...</a></b> should be changed to <a><b>...</b></a> 
> only if the <a>...</a> element is the unique child node of <b>...</b>
> 
> How can I do this?
> 
> Thanks,
> 
> Ken
> 
> ******************************
> Kenneth R. Beesley, D.Phil.
> P.O. Box 540475
> North Salt Lake, UT
> 84054  USA

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.