0

I'm trying to write a transform to parse an html document and create another html document but I can't seem to use the html tags in the xslt.

My html source that I want to apply the transform on looks like this:

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
    </head>
    <body class="3-column">
        <div class="centercol"><p>Hello world</p></div>
         <div class="leftcol">
                    <div id="menu">

                    </div>
          </div>
         <div class="rightcol"> </div>
    </body>
</html>

My XSLT looks like this:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
    <xsl:template match="/*">
        <xsl:value-of select="body/div/p"/>
    </xsl:template>
</xsl:stylesheet>

Can anyone help me figure out how to get my xpaths to work with html tags?

Edited by baltazar

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by Mike Askew
0
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:x="http://www.w3.org/1999/xhtml" version="1.0">
  <xsl:template match="/*">
    <xsl:value-of select="x:body/x:div/x:p"/> //note changes to this line
  </xsl:template>
</xsl:stylesheet>

I've assigned the HTML namespace to x, so now we prefix all references to the XML with x: and then you can find the nodes you were missing before :)

Proof in action:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:x="http://www.w3.org/1999/xhtml" version="1.0">
  <xsl:template match="/*">
    <xsl:value-of select="x:body/x:div/x:p"/>
  </xsl:template>
</xsl:stylesheet>

run on

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title></title>
  </head>
  <body class="3-column">
    <div class="centercol">
      <p>Hello world</p>
    </div>
    <div class="leftcol">
      <div id="menu">
      </div>
    </div>
    <div class="rightcol"> </div>
  </body>
</html>

gives:

<?xml version="1.0" encoding="utf-8"?>Hello world

Edited by Mike Askew: added proof

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.