[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Coalesce namespaces for XHTML
xsl:copy-of produces an exact copy, namespace prefixes and all. If you want to change prefixes, you need to use xsl:element as in your example. Michael Kay http://www.saxonica.com/ > -----Original Message----- > From: Adam Retter [mailto:adam.retter@xxxxxxxxxxxxxx] > Sent: 09 February 2009 21:00 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: Coalesce namespaces for XHTML > > Hi there, > > I am trying to generate XHTML content that can be delivered > as text/html, which means that all elements must be in the > default namespace of xmlns="http://www.w3.org/1999/xhtml" > > I have some source XML documents that contain some XML in my > own namespace and also some XHTML snippets, I wish to copy > these XHTML snippets into my output document, a simple > example follows - > > <?xml version="1.0" encoding="UTF-8"?> > <o:a xmlns:o="http://other" xmlns:xh="http://www.w3.org/1999/xhtml"> > <o:b> > <xh:a href="http://somewebsite.com" title="some other > website">some website</xh:a> > </o:b> > </o:a> > > > > <?xml version="1.0" encoding="UTF-8"?> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > version="2.0" xmlns:o="http://other" > xmlns:xh="http://www.w3.org/1999/xhtml" > xmlns="http://www.w3.org/1999/xhtml"> > <xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" > doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" > media-type="text/html" method="xhtml"/> > > <xsl:template match="o:a"> > <html> > <body> > <xsl:apply-templates/> > </body> > </html> > </xsl:template> > > <xsl:template match="o:b"> > <xsl:apply-templates/> > </xsl:template> > > <xsl:template match="xh:a"> > <xsl:copy-of select="."/> > </xsl:template> > > </xsl:stylesheet> > > > > > Which generates the following output (Saxon 9.1.0.3) - > > <?xml version="1.0" encoding="UTF-8"?> > <!DOCTYPE html > PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> > <html xmlns="http://www.w3.org/1999/xhtml" xmlns:o="http://other" > xmlns:xh="http://www.w3.org/1999/xhtml"> > <body> > > <xh:a href="http://somewebsite.com" title="some other > website">some website</xh:a> > > > </body> > </html> > > > Now it all looks fine apart from the copied elements have > kept their namespace prefix of xh: and not been places in the > default namespace. > The xh namespace and the default namespace are actually the > same. In case thats not very clear, the output I wish to > generate would look like this - > > <?xml version="1.0" encoding="UTF-8"?> > <!DOCTYPE html > PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> > <html xmlns="http://www.w3.org/1999/xhtml" xmlns:o="http://other" > xmlns:xh="http://www.w3.org/1999/xhtml"> > <body> > > <a href="http://somewebsite.com" title="some other > website">some website</a> > > > </body> > </html> > > > I can achieve that if I replace the template that matches > xh:a with the following - > > <xsl:template match="xh:a"> > <xsl:element name="{local-name()}"> > <xsl:copy-of select="@*|text()"/> > </xsl:element> > </xsl:template> > > However it does not seem like a good solution - is there a > better way of achieving this? > > Thanks Adam. > > > -- > Adam Retter
|
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
|