Altova Mailing List Archives


RE: [xsl] Noobie: normalize ... to ...

From: "Michael Kay" <mike@--------.--->
To: <xsl-list@-----.------------.--->
Date: 2/18/2010 6:10:00 PM
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@g...] 
> Sent: 18 February 2010 17:55
> To: xsl-list@l...
> Subject: [xsl] 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
> 
> 
> 
> 
> 
> 
> --~------------------------------------------------------------------
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> or e-mail: <mailto:xsl-list-unsubscribe@l...>
> --~--
> 


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe@l...>
--~--

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.