XSL Transformation output -- no tags -- Help!

M

Mike Conmackie

Hi Folks,

I've probably omitted something very basic but I have no idea what it might
be. The results of my transformation _should_ be an xml file but all I get
is the xml declaration immediately followed by the input node text values in
one long string -- no xml tags (barring the xml declaration, of course)
appear in the output file. Anyone who wants to see either the input xml
file or the xsl file, please let me know and I will e-mail them to you.
Thanks.

Regards,

Mike Conmackie
(e-mail address removed)
 
D

dan

Mike Conmackie said:
The results of my transformation _should_ be an xml file but all I get
is the xml declaration immediately followed by the input node text values in
one long string
<snip>


I would guess you are using <xsl:value-of> when what it sounds like
you need is <xsl:copy-of>
 
M

Mike Conmackie

Dan,

The purpose of the transformation is to translate one tag set into another
(with slightly different output structure). Therefore, I don't think that
<xsl:copy-of> is what I want. Would you like to look at the input document
and the stylesheet? I can also show you a sample of the expected output.

Mike
 
B

Ben Edgington

Hi again,

Mike Conmackie said:
I've probably omitted something very basic but I have no idea what it might
be. The results of my transformation _should_ be an xml file but all I get
is the xml declaration immediately followed by the input node text values in
one long string -- no xml tags (barring the xml declaration, of course)
appear in the output file. Anyone who wants to see either the input xml
file or the xsl file, please let me know and I will e-mail them to you.

This is what happens when no template in your XSL transformation
matches anything in the input XML - the built-in template rules
take over, which basically just copy the node contents.
See http://www.w3.org/TR/xslt#built-in-rule

Example:

This XML:
<a>
<b>Some stuff</b>
<c>Some other stuff</c>
</a>


With this XSLT:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
<!-- Main template matches nothing in the input -->
<xsl:template match="/x">
<xsl:text>Hello, world!</xsl:text>
</xsl:template>

</xsl:stylesheet>


Gives this output:
<?xml version="1.0" encoding="UTF-8"?>
Some stuff
Some other stuff


Ie. just a copy of the node contents. Note that we *don't* see
"Hello, world!" which shows that the main template was did not match
anything.

This might be your problem. If you stick in a recursive copy it will
over-ride the built-in rules and match anything not already matched by
other templates. Therefore nodes you don't explicitly process are
just copied to the output (the identity transformation)

This is the version given in the W3C Rec:
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>


However, I prefer this two-template one as I generally don't want to
copy namespaces to my output:
<xsl:template match="node()">
<xsl:element name="{name()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>

<xsl:template match="@*|text()|comment()|processing-instruction()">
<xsl:copy/>
</xsl:template>


Ben
 
M

Mike Conmackie

Hello All,

Ben's statement regarding the non-matching status of any template in the
stylesheet was the real issue. I removed the namespace prefix from the
input document and the styelsheet and life became much better. As usual,
thanks to all who offered assistance.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top