Dear XSL newsgroup I have input XHTML (indirectly produced from MS Word) and I am using XSLT to produce an output XHTML document. The input XHTML contains many topics, the transform selects one topic of interest and the output XHTML can be displayed as a web page. I have ensured the input is well-formed and valid. In the transform I am trying to produce all my XHTML by means of a single <xsl:template match="/"> which includes all the output <html> ... </html> elements. My problem is that within the <xsl:template match="/"> element, all use of xsl:value-of seems incapable of retrieving anything from the input XHTML. Here are the documents: ----------------input.xhtml------------------- <?xml version="1.0"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Fruits</title> </head> <body> <h1>Apples</h1> <p>Round fruits that grow on trees.</p> <h1>Bananas</h1> <p>Yellow fruits that grow in clumps.</p> </body> </html> ----------------input.xhtml------------------- ----------------transform.xslt------------------- <xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml" exclude-result-prefixes="xhtml xsl"> <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/> <xsl:template match="/"> <html> <head> <title> Title: <xsl:value-of select="xhtml:title"/> </title> </head> <body> Body: <xsl:value-of select="xhtml:p"/> </body> </html> </xsl:template> </xsl:stylesheet> ----------------transform.xslt------------------- -------------output.html------------ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> Title: </title> </head> <body> Body: </body> </html> -------------output.html------------ Although the output is valid it's not picking up the xhtml:title or xhtml:p elements from the input. Any help would be greatly appreciated! Kind regards Will Rayer
I'm not sure what you're actually trying to accomplish, but your XPath is incorrect. Try this: <xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xhtml xsl"> <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/> <xsl:template match="/"> <html> <head> <title> Title: <xsl:value-of select="xhtml:html/xhtml:head/xhtml:title"/> </title> </head> <body> Body: <xsl:value-of select="xhtml:html/xhtml:body/xhtml:p"/> </body> </html> </xsl:template> </xsl:stylesheet> ML --- Matija Lah, SQL Server MVP http://milambda.blogspot.com/
Thanks, that works great! I didn't realize you had to qualify each element in the XPath with the namespace, I thought it was the top element only. What I am trying to do is as follows. I have a large Word doc containing many topics. I am converting the Word doc into XHTML and then selecting one topic via xsl:param in the stylesheet and outputting the topic as a stand-alone XHTML document. The conversion of Word to XHTML works fine, as does the xsl:param part of my stylesheet. Thus I did not include them in my example. My problem was extracting elements from the Word XHTML, which I can do now due to your kind advice. Many thanks, Will Rayer "ML" wrote: > I'm not sure what you're actually trying to accomplish, but your XPath is > incorrect. > > Try this: > > <xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" > xmlns:xhtml="http://www.w3.org/1999/xhtml" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > exclude-result-prefixes="xhtml xsl"> > <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" > doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" > doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/> > <xsl:template match="/"> > <html> > <head> > <title> Title: <xsl:value-of select="xhtml:html/xhtml:head/xhtml:title"/> > </title> > </head> > <body> Body: <xsl:value-of select="xhtml:html/xhtml:body/xhtml:p"/> > </body> > </html> > </xsl:template> > </xsl:stylesheet> > > > ML > > --- > Matija Lah, SQL Server MVP > http://milambda.blogspot.com/
I see. Well, let us know if you have any other problems. :) ML --- Matija Lah, SQL Server MVP http://milambda.blogspot.com/