Go Back   Velocity Reviews > Newsgroups > XML
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

XML - xsl:template not getting matched

 
Thread Tools Search this Thread
Old 05-18-2006, 12:33 AM   #1
Default xsl:template not getting matched


Hello:
I am stumped on what I belive to be a namespace issue. The XSL, source
XML, and result XML are included below. The problem is that the
template to match "getBalances" is never invoked by the
apply-templates. If I remove the default namespace in the source XML's
getBalance element, the problem goes away and the template is matched.

I spent several hours searching the newsgroups but in vain. Any help
would be appreciated.

Thanks

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

xmlns:fo="http://www.w3.org/1999/XSL/Format"

xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:impl="http://city.com/ziggy/">

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="SOAP-ENV:Envelope">
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:impl="http://city.com/ziggy/"
xmlnssd="http://www.w3.org/2001/XMLSchema">
<xsl:apply-templates select="SOAP-ENV:Header"/>
<xsl:apply-templates select="SOAP-ENV:Body"/>
</SOAP-ENV:Envelope>
</xsl:template>

<xsl:template match="SOAP-ENV:Header">
<!-- copy children without any modifications -->
<xsl:copy-of select="."/>
</xsl:template>

<xsl:template match="SOAP-ENV:Body">
<SOAP-ENV:Body>
<xsl:apply-templates select="getBalances"/>
</SOAP-ENV:Body>
</xsl:template>

<xsl:template match="getBalances">
<xsl:text> HERE ! </xsl:text>
</xsl:template>
</xsl:stylesheet>

==source xml==
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlnssd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<getBalances xmlns="http://city.com/ziggy/">123456</getBalances>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

==result xml==
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:impl="http://city.com/ziggy/"
xmlnssd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Header/>
<SOAP-ENV:Body/>
</SOAP-ENV:Envelope>



tentstitcher@gmail.com
  Reply With Quote
Old 05-18-2006, 12:39 AM   #2
Joe Kesselman
 
Posts: n/a
Default Re: xsl:template not getting matched

wrote:
> apply-templates. If I remove the default namespace in the source XML's
> getBalance element, the problem goes away and the template is matched.


Use a prefixed name such as ziggy:getBalance, and add a declaration for
that prefix to your stylesheet.

XSLT is namespace-aware. You have to work with that. It is possible to
achieve namespace-insensitive matching via predicates, but it's
gawdawful ugly and emphatically the wrong thing to do.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
  Reply With Quote
Old 05-18-2006, 01:16 AM   #3
tentstitcher@gmail.com
 
Posts: n/a
Default Re: xsl:template not getting matched

Joe,
Thanks for the quick response. It seems to be working fine after I
applied your suggested fix.

Thanks


Joe Kesselman wrote:
> wrote:
> > apply-templates. If I remove the default namespace in the source XML's
> > getBalance element, the problem goes away and the template is matched.

>
> Use a prefixed name such as ziggy:getBalance, and add a declaration for
> that prefix to your stylesheet.
>
> XSLT is namespace-aware. You have to work with that. It is possible to
> achieve namespace-insensitive matching via predicates, but it's
> gawdawful ugly and emphatically the wrong thing to do.
>
> --
> () ASCII Ribbon Campaign | Joe Kesselman
> /\ Stamp out HTML e-mail! | System architexture and kinetic poetry


  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump