Click to See Complete Forum and Search --> : Why XSL wo template still convert xml to html, which prints all text node in xml?


AprilWeb
05-16-2010, 01:11 AM
Hi,

I have the following xml, xsl and output from firefox when loading the xml.

The xsl is virtually useless, since it just have the stylesheet tag without any real content. I suppose when I load the xml in firefox, firefox should print the real xml file itself, as if the xsl doesn't exist (<?xml-stylesheet type="text/xsl" href="book.xsl"?>), since there is no real data in it. But instead I get all the text node printed.

Why is that? Is there anyway to avoid all the text node from being printed?

XML:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="book.xsl"?>
<main>
<boulevard>
<block>Panorama Street</block>
<block>Panorama Street</block>
</boulevard>
<parkway>
<thoroughfare name="Whitesburg Drive">
<sidestreet>Bob Wallace Avenue</sidestreet>
<sidestreet>Woodridge Street</sidestreet>
</thoroughfare>
</parkway>
</main>

XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0" >
<xsl:output method="text" />
</xsl:stylesheet>

output:

Panorama Street
Panorama Street

Bob Wallace Avenue
Woodridge Street


Thanks,
April

Charles
05-16-2010, 01:44 PM
Why is that? Is there anyway to avoid all the text node from being printed?Because that's what's supposed to happen when you omit the templates. You need to add some templates. What do you want the stylesheet to do?

AprilWeb
05-16-2010, 03:13 PM
Charles,

I had an template,

<xsl:template match="parkway">
match found
</xsl:template>

However, the output is:

Panorama Street <-- text node of "parkway"'s sibling node "blvd/block"

match found

I only expect "match found", why "street" is also printed? It's not a child text node of "parkway"! Please help!

Here is the xml:
XML:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="book.xsl"?>
<main>
<boulevard>
<block>Panorama Street</block>
<block>Panorama Street</block>
</boulevard>
<parkway>
<thoroughfare name="Whitesburg Drive">
<sidestreet>Bob Wallace Avenue</sidestreet>
<sidestreet>Woodridge Street</sidestreet>
</thoroughfare>
</parkway>
</main>


Thanks,
April

Charles
05-17-2010, 12:09 PM
<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates select = "//parkway"/>
</xsl:template>

<xsl:template match="parkway">
<xsl:text>match found</xsl:text>
</xsl:template>
</xsl:stylesheet>