473,803 Members | 4,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Comments and DOCTYPES

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><x sl: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_t ype SYSTEM "CommonDeviceTy pe.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
Jul 20 '05 #1
2 1409


Wendy Shuya wrote:
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><x sl: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 />
</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?


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.


--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
In article <dd************ **************@ posting.google. com>,
Wendy Shuya <we********@hot mail.com> wrote:
<xsl:templat e match="comment( )">
<xsl:comment><x sl:value-of select="."/></xsl:comment>
</xsl:template> <xsl:templat e 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
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
2755
by: lkrubner | last post by:
I've got a PHP application that's 2 megs in size. Of that, my guess is 200k-400k is comments. Do they impose a performance hit? I've been postponing any kind of optimization, but at some point I'll have to do it. Is taking out the comments worth it? Of all the optimizations I can do, where should it rank?
4
10940
by: Uwe Ziegenhagen | last post by:
Hello, my fellows and me implement a c++ tool that is able to divide blank/tab separated files into <number>, <text>, <c-singlelinecomment> and <multilinecomment>. So far it's not working bad, we have just one problem if I call the a.exe that gcc compiles with the following textfile (./a.exe < test.txt) he does not match the multiline comments correctly. *test.txt contains:
15
2004
by: Viken Karaguesian | last post by:
Hello all, I'm having a problem with DOCTYPES. Until now, I haven't been specifying doctypes. I want to start specifying doctypes, but am having trouble doing so. Whenever I specify a doctype, *any* doctype, *I almost always* get a horizontal scroll bar in IE, but not in Firefox/Opera. It seems as if the page stretches beyond the browsers borders. Even if I set ultra-narrow margins and only have one word on the page, I get a
28
3466
by: Benjamin Niemann | last post by:
Hello, I've been just investigating IE conditional comments - hiding things from non-IE/Win browsers is easy, but I wanted to know, if it's possible to hide code from IE/Win browsers. I found <!> in the original MSDN documentation, but this is (although it is working) unfortunately non-validating gibberish. So I fooled around trying to find a way to make it valid. And voila: <!--><!><!-->
40
4649
by: Edward Elliott | last post by:
At the risk of flogging a dead horse, I'm wondering why Python doesn't have any multiline comments. One can abuse triple-quotes for that purpose, but that's obviously not what it's for and doesn't nest properly. ML has a very elegant system for nested comments with (* and *). Using an editor to throw #s in front of every line has limitations. Your editor has to support it and you have to know how to use that feature. Not exactly...
7
1888
by: Bob Stearns | last post by:
Several weeks ago I asked what comments I could pass to DB2 in a SELECT statement. I don't remember whether I said via PHP/ODBC. I was assured that both /* */ style comment blocks and -- comment lines were allowed. Unfortunately, neither work. Both -- and /* */ comments cause a "premature end of statement". Any sage advice?
98
4632
by: tjb | last post by:
I often see code like this: /// <summary> /// Removes a node. /// </summary> /// <param name="node">The node to remove.</param> public void RemoveNode(Node node) { <...> }
40
2683
by: jacob navia | last post by:
Recently we had poor Mr "teapot" that was horrified at the heresy of lcc-win of accepting // comments. C is a nice language, and you can do anything with it, inclusive a program that transforms // comments into well behaved /* ... */ ones... ------------------------------------------------cut here /*
0
9703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9564
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.