xsl:template not getting matched

T

tentstitcher

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"
xmlns:xsl="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/"
xmlns:xsd="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/"
xmlns:xsd="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/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Header/>
<SOAP-ENV:Body/>
</SOAP-ENV:Envelope>
 
J

Joe Kesselman

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.
 
T

tentstitcher

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

Thanks
 

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,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top