Comments and DOCTYPES

Discussion in 'XML' started by Wendy Shuya, Apr 1, 2004.

  1. Wendy Shuya

    Wendy Shuya Guest

    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
    Wendy Shuya, Apr 1, 2004
    #1
    1. Advertising

  2. 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><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 />
    </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/
    Martin Honnen, Apr 2, 2004
    #2
    1. Advertising

  3. In article <>,
    Wendy Shuya <> wrote:

    ><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
    Richard Tobin, Apr 2, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,117
  2. JWL

    Mixing doctypes

    JWL, Oct 13, 2006, in forum: HTML
    Replies:
    5
    Views:
    1,197
    David Dorward
    Oct 16, 2006
  3. UKuser
    Replies:
    2
    Views:
    352
    C A Upsdell
    Feb 4, 2009
  4. the.computational biologist

    including xml entities with their own doctypes

    the.computational biologist, Jul 21, 2011, in forum: XML
    Replies:
    5
    Views:
    1,278
    Joe Kesselman
    Jul 23, 2011
  5. Daniel Harple
    Replies:
    0
    Views:
    110
    Daniel Harple
    Dec 23, 2005
Loading...

Share This Page