You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Steve Dwire <st...@netsteps.net> on 2002/03/29 22:32:29 UTC

xsl:copy-of loses node names

I have an XML document that I’m converting to SQL statements using xalanj
2.1

Most of the nodes I’m converting, but there’s one node type I want to store
in the database as a giant block of XML. I’ve got a template that’s supposed
to turn the following:

<node><child>Child1</child><child>Child2></child></node>

into

‘<child>Child1</child><child>Child2></child>’

What I get instead is

‘Child1Child2’

The template looks like this:

<xsl:template name="xml_param">
            <xsl:param name="xml" />
            <xsl:param name="allow_null" select="true()" />
            <xsl:choose>
                        <xsl:when test="boolean($xml) or
($allow_null=false())">
                                    <xsl:text>'</xsl:text>
                                    <xsl:copy-of select="$xml" />
                                    <xsl:text>'</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>NULL</xsl:otherwise>
            </xsl:choose>
</xsl:template>

and I call it as

<xsl:call-template name=”xml_param”>
            <xsl:with-param select=”node”>
</xsl:call-template>

The examples I’ve seen at http://www.dpawson.co.uk/xsl/sect2/N1930.html lead
me to believe this is the correct syntax, but it doesn’t seem to be working.

If it matters, my stylesheet contains the following element:

<xsl:output method="text" omit-xml-declaration="yes" indent="no" />

Would this cause my problems or is it something else?

Steve Dwire
Netsteps, Inc.
500 Park Blvd., Suite 295-C
Itasca, IL 60143
Voice - (630) 250-3045 x104
Fax - (630) 250-3046


Re: copy-of loses node names

Posted by "Frank E. Weiss" <fr...@well.com>.
I tried your example. See what happens when you use <xsl:output method="xml"/>. The XSLT spec says the text output
method outputs only text nodes.


RE: copy-of loses node names

Posted by Steve Dwire <st...@netsteps.net>.
1) I’m using the version of xerces that comes bundled with Xalan 2.1.0,
whichever that one is…

2) I’ll accept that to get what I said I expected I’d need to include /kid
in the select statement. Then, let me change my expectation to be

‘<parent><kid>Kid1</kid><kid>Kid2</kid></parent>’

when I just pass it doc_root/parent. I’m still only getting Kid1Kid2 as
output.

Steve Dwire
Netsteps, Inc.
500 Park Blvd., Suite 295-C
Itasca, IL 60143
Voice - (630) 250-3045 x104
Fax - (630) 250-3046

-----Original Message-----
From: Karthik Gurumurthy [mailto:karthikg@aztec.soft.net]
Sent: Monday, April 01, 2002 9:17 PM
To: Steve Dwire; xalan-j-users@xml.apache.org
Subject: RE: copy-of loses node names

From: Steve Dwire [mailto:steve.dwire@netsteps.net] wrote
I think there’s some confusion with my mocked-up xml names. Let’s change it
to read as following:

<doc_root><parent><kid>Kid1</kid><kid>Kid2</kid></parent></doc_root>

and what I expect is

‘<kid>Kid1</kid><kid>Kid2</kid>’

and what I get is

‘Kid1Kid2’

when I call

<xsl:call-template name=”xml_param”>
            <xsl:with-param name=”xml” select=”/doc_root/parent” />
</xsl:call-template name=”xml_param”>

with this template:

<xsl:template name="xml_param">
            <xsl:param name="xml" />
            <xsl:param name="allow_null" select="true()" />
            <xsl:choose>
                        <xsl:when test="boolean($xml) or
($allow_null=false())">
                                    <xsl:text>'</xsl:text>
                                    <xsl:copy-of select="$xml" />
                                    <xsl:text>'</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>NULL</xsl:otherwise>
            </xsl:choose>
</xsl:template>
[karthik Guru]
First which transformer are you using? second for the output you desire, as
i had already mentioned in my earlier mail,
this s'd be the param passed to the template. You have to have kid too in
the selected nodelist that you are passing.
Otherwise you will get "parent" node too in the output. I tried this using
saxon and xalan it worked just fine ( i got the output you wanted)
<xsl:with-param name=”xml” select=”/doc_root/paren/kid ” />

HTH,
karthik

RE: copy-of loses node names

Posted by Karthik Gurumurthy <ka...@aztec.soft.net>.
From: Steve Dwire [mailto:steve.dwire@netsteps.net] wrote
I think there's some confusion with my mocked-up xml names. Let's change
it to read as following:

<doc_root><parent><kid>Kid1</kid><kid>Kid2</kid></parent></doc_root>
 
and what I expect is
 
'<kid>Kid1</kid><kid>Kid2</kid>'
 
and what I get is 
 
'Kid1Kid2'
 
when I call
 
<xsl:call-template name="xml_param">
            <xsl:with-param name="xml" select="/doc_root/parent" />
</xsl:call-template name="xml_param">
 
with this template:
 
<xsl:template name="xml_param">
            <xsl:param name="xml" />
            <xsl:param name="allow_null" select="true()" />
            <xsl:choose>
                        <xsl:when test="boolean($xml) or
($allow_null=false())">
                                    <xsl:text>'</xsl:text>
                                    <xsl:copy-of select="$xml" />
                                    <xsl:text>'</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>NULL</xsl:otherwise>
            </xsl:choose>
</xsl:template>
[karthik Guru]  
First which transformer are you using? second for the output you desire,
as i had already mentioned in my earlier mail,
this s'd be the param passed to the template. You have to have kid too
in the selected nodelist that you are passing.
Otherwise you will get "parent" node too in the output. I tried this
using saxon and xalan it worked just fine ( i got the output you wanted)
<xsl:with-param name="xml" select="/doc_root/paren/kid " />
 
HTH,
karthik
 

-----Original Message-----
From: Karthik Gurumurthy [mailto:karthikg@aztec.soft.net]
Sent: Monday, April 01, 2002 1:03 AM
To: Steve Dwire; xalan-j-users@xml.apache.org
Subject: RE: copy-of loses node names
 
 
steve.dwire@netsteps.net <ma...@netsteps.net>   wrote: 
 I've got a template that's supposed to turn the following:
 
<node><child>Child1</child><child>Child2></child></node>
 
into 
 
'<child>Child1</child><child>Child2></child>'
 
What I get instead is
 
'Child1Child2'
 
The template looks like this:
 
<xsl:template name="xml_param">
            <xsl:param name="xml" />
            <xsl:param name="allow_null" select="true()" />
            <xsl:choose>
                        <xsl:when test="boolean($xml) or
($allow_null=false())">
                                    <xsl:text>'</xsl:text>
                                    <xsl:copy-of select="$xml" />
                                    <xsl:text>'</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>NULL</xsl:otherwise>
            </xsl:choose>
</xsl:template>
 
 
<xsl:call-template name="xml_param">
            <xsl:with-param select="node">
</xsl:call-template>
[karthik Guru]  it s'd be node( ) and not just node ..probably a typo??
<wink/>
i guess it s'd work.
For the output you are expecting , it s''d be 
            <xsl:with-param select= "node/child">
 

HTH
karthik.
 

RE: copy-of loses node names

Posted by Steve Dwire <st...@netsteps.net>.
I think there’s some confusion with my mocked-up xml names. Let’s change it
to read as following:

<doc_root><parent><kid>Kid1</kid><kid>Kid2</kid></parent></doc_root>

and what I expect is

‘<kid>Kid1</kid><kid>Kid2</kid>’

and what I get is

‘Kid1Kid2’

when I call

<xsl:call-template name=”xml_param”>
            <xsl:with-param name=”xml” select=”/doc_root/parent” />
</xsl:call-template name=”xml_param”>

with this template:

<xsl:template name="xml_param">
            <xsl:param name="xml" />
            <xsl:param name="allow_null" select="true()" />
            <xsl:choose>
                        <xsl:when test="boolean($xml) or
($allow_null=false())">
                                    <xsl:text>'</xsl:text>
                                    <xsl:copy-of select="$xml" />
                                    <xsl:text>'</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>NULL</xsl:otherwise>
            </xsl:choose>
</xsl:template>

Steve Dwire
Netsteps, Inc.
500 Park Blvd., Suite 295-C
Itasca, IL 60143
Voice - (630) 250-3045 x104
Fax - (630) 250-3046

-----Original Message-----
From: Karthik Gurumurthy [mailto:karthikg@aztec.soft.net]
Sent: Monday, April 01, 2002 1:03 AM
To: Steve Dwire; xalan-j-users@xml.apache.org
Subject: RE: copy-of loses node names


steve.dwire@netsteps.net <ma...@netsteps.net>   wrote:
 I’ve got a template that’s supposed to turn the following:

<node><child>Child1</child><child>Child2></child></node>

into

‘<child>Child1</child><child>Child2></child>’

What I get instead is

‘Child1Child2’

The template looks like this:

<xsl:template name="xml_param">
            <xsl:param name="xml" />
            <xsl:param name="allow_null" select="true()" />
            <xsl:choose>
                        <xsl:when test="boolean($xml) or
($allow_null=false())">
                                    <xsl:text>'</xsl:text>
                                    <xsl:copy-of select="$xml" />
                                    <xsl:text>'</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>NULL</xsl:otherwise>
            </xsl:choose>
</xsl:template>


<xsl:call-template name=”xml_param”>
            <xsl:with-param select=”node”>
</xsl:call-template>
[karthik Guru]  it s'd be node( ) and not just node ..probably a typo??
<wink/>
i guess it s'd work.
For the output you are expecting , it s''d be
            <xsl:with-param select= "node/child”>

HTH
karthik.


RE: copy-of loses node names

Posted by Karthik Gurumurthy <ka...@aztec.soft.net>.
steve.dwire@netsteps.net <ma...@netsteps.net>   wrote: 
 I've got a template that's supposed to turn the following:
 
<node><child>Child1</child><child>Child2></child></node>
 
into 
 
'<child>Child1</child><child>Child2></child>'
 
What I get instead is
 
'Child1Child2'
 
The template looks like this:
 
<xsl:template name="xml_param">
            <xsl:param name="xml" />
            <xsl:param name="allow_null" select="true()" />
            <xsl:choose>
                        <xsl:when test="boolean($xml) or
($allow_null=false())">
                                    <xsl:text>'</xsl:text>
                                    <xsl:copy-of select="$xml" />
                                    <xsl:text>'</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>NULL</xsl:otherwise>
            </xsl:choose>
</xsl:template>
 

<xsl:call-template name="xml_param">
            <xsl:with-param select="node">
</xsl:call-template>
[karthik Guru]  it s'd be node( ) and not just node ..probably a typo??
<wink/>
i guess it s'd work.
For the output you are expecting , it s''d be 
            <xsl:with-param select= "node/child">
 
HTH
karthik.