|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
XSLT: Namespace problems
Hi,
I have two problems... 1. How do you differentiate the same elements in two documents with the same namespace? I want to combine the bodies of two XHTML documents, but can't figure out how to reference the body element of the other document... It's read with the document function, but it won't apply the template because I don't know how to specify it here. Assuming this could be resolved how do you stop it infinitely recursing? The stylesheet should take the input file given to the parser dump it between the second div element and another from the document function and dump that between the first div element. <?xml version="1.0" encoding="UTF-8"?> <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml"> <xsl utput method = "xml"version = "1.0" omit-xml-declaration = "no" encoding = "UTF-8" indent = "yes" doctype-public = "-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/> <xsl:template match="/"> <xsl:apply-templates/> </xsl:template> <xsl:template match="xhtml:html"> <html> <xsl:copy-of select="xhtml:head"/> <xsl:apply-templates select="xhtml:body"/> </html> </xsl:template> <xsl:template match="xhtml:body"> <body> <!-- *** copy body of full.xml *** --> <div id="leftcontent"> <xsl:apply-templates select="document('full.xml')/html/body"/> </div> <!-- *** copy body of xml doc given to parser *** --> <div id="rightcontent"> <xsl:apply-templates/> </div> </body> </xsl:template> <xsl:template match="node()|@*"> <xsl:copy-of select="."/> </xsl:template> </xsl:transform> 2. The first problem encountered was with the inclusion of the doctype in the source file caused no output. This was remedied by including the xhtml namespace, but this appears in the html element output as an attribute... is there anyway to remove this? An xmlns attribute also appeared in the elements taken from the file read by the document function during testing (it output because it wasn't html, just some random xml for testing purposes). <?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:xhtml="http://www.w3.org/1999/xhtml"> <head> <title>hi</title> </head> <body> <!-- no output --><div id="leftcontent"/> <!-- this div contains a copy of the contents of body element in the file given to parser --> <div id="rightcontent"> <p>bye</p> </div> </body> </html> Any help is appreciated, Aragon Last edited by aragon : August 1st, 2003 at 04:45 PM. |
|
#2
|
|||
|
|||
|
Ok, I sorted the first problem... an examples is posted for reference.
The namespace comes after the document function, like so... <xsl:template match="xhtml:body"> <xsl aram name="main">yes</xsl aram><xsl:choose> <xsl:when test="$main='yes'"> <xsl:apply-templates select="document($leftDocument)/xhtml:html/xhtml:body"> <xsl:with-param name="main">no</xsl:with-param> </xsl:apply-templates> <div id="rightcontent"> <xsl:apply-templates /> </div> </xsl:when> <xsl therwise><div id="leftcontent"> <xsl:apply-templates /> </div> </xsl therwise></xsl:choose> </xsl:template> Still stuck with the second one though... it outputs <html xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml"> I want it to output <html xmlns="http://www.w3.org/1999/xhtml"> or <html> Cheers, Aragon |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > XSLT: Namespace problems |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|