CDATA and template matching

S

Shannon Hughes

I created a simple 7 line stylesheet in XML Spy that is matching certain
elements (table names) used to created some SQL syntax in the result file. I
had to do this for 4 different Elements so I created 4 different
stylesheets. Two of them are working as expected. The other two are printing
out the correct values to the result file but are also including all my
CDATA information from elements that do not match the template match clause.
Any ideas what I am doing wrong? This is my first day using XSLT.

Shannon Hughes
FVBC Webmaster
http://www.fvbaptist.org
 
S

Shannon Ray Hughes

This is my stylesheet below:

<?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">

<xsl:eek:utput method="text" encoding="us-ascii" media-type="text/plain"
indent="no" cdata-section-elements=""/>

<xsl:template match="SERVICE_MEASUREMENT">

<xsl:text>DROP TABLE </xsl:text>

<xsl:value-of select="@DB_NAME"/>

<xsl:text>;
</xsl:text>
</xsl:template>

</xsl:stylesheet>

The "DROP TABLE" string is being copied to the result file correctly but all
the CDATA information from other elements that do not match the template are
also being copied to the result file.

Thanks for your help.
 
D

Dimitre Novatchev

This confirms my guess that the unexpected output is result from the
built-in templates.

Either specify empty rules (templates) for the nodes you don't want
processed, or specify explicitly (in the "select" attribute of
xsl:apply-templates) what is to be processed by xsl:apply-templates.

Once again -- do read about built-in templates.


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
 
S

Shannon Ray Hughes

Thanks so much, that did the trick....I forced the apply-templates element:

<?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">

<xsl:eek:utput method="text" indent="no" />

<xsl:template match="/">

<xsl:apply-templates select="//SERVICE_MEASUREMENT |
//SUBSCRIBER_MEASUREMENT"/>

</xsl:template>

<xsl:template match="SERVICE_MEASUREMENT | SUBSCRIBER_MEASUREMENT">

<xsl:text>Found it
</xsl:text>

</xsl:template>

</xsl:stylesheet>
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top