Comments and DOCTYPES

W

Wendy Shuya

I am in the process of translating a large set of XML files. I've run
into some problems and thought someone may be able to assist.

Problem 1: Comments
-------------------
I need to match the comments (<!-- -->)in the original XML file, and
output them to the translated file. The code I have to do this:
<xsl:template match="comment()">
<xsl:comment><xsl:value-of select="."/></xsl:comment>
</xsl:template>

This template code seems to work fine if this is the "only" template
in my .xslt file. As soon as I add another template (for example):
<xsl:template match="/Project">
<xsl:apply-templates mode="copy" select="."/>
</xsl:template>

the comments are no longer printed. How can ensure that all comments
are going to be output?

Problem 2: DOCTYPE
------------------
The first few lines of original xml file includes something like:
<!DOCTYPE Project [
<!ENTITY common_device_type SYSTEM "CommonDeviceType.xml">
]>

I need to be able to conserve these lines of text and output them to
the translated file. Currently, I don't how to match on this text.

Secondly, further down in the file is a reference to this entity:
&common_device_type;

I don't want this entity to be expanded, but instead I want to just
keep the text output as original.

If anyone could offer any suggestions on how to do these things, it
would be much appreciated.

Thank you for your time,
Wendy Shuya
 
M

Martin Honnen

Wendy said:
I am in the process of translating a large set of XML files. I've run
into some problems and thought someone may be able to assist.

Problem 1: Comments
-------------------
I need to match the comments (<!-- -->)in the original XML file, and
output them to the translated file. The code I have to do this:
<xsl:template match="comment()">
<xsl:comment><xsl:value-of select="."/></xsl:comment>
</xsl:template>

If you want to copy a comment node then you can simply use
<xsl:template match="comment()">
<xsl:copy />
This template code seems to work fine if this is the "only" template
in my .xslt file. As soon as I add another template (for example):
<xsl:template match="/Project">
<xsl:apply-templates mode="copy" select="."/>
</xsl:template>

the comments are no longer printed. How can ensure that all comments
are going to be output?

You will have to somehow recursively apply-templates to child nodes so
that they are processed. The above snippet doesn't show what you are
doing but I suspect processing never reaches the comment nodes.
 
R

Richard Tobin

Wendy Shuya said:
<xsl:template match="comment()">
<xsl:comment><xsl:value-of select="."/></xsl:comment>
</xsl:template>
<xsl:template match="/Project">
<xsl:apply-templates mode="copy" select="."/>
</xsl:template>

I can't be sure without seeing your whole stylesheet, but notice that
the second template calls apply-templates with mode=copy, and the
first template does not have mode=copy.

-- Richard
 

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,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top