Excluding Child for Repurposing with XML and XSLT

Discussion in 'XML' started by Eric Weiss, Jul 6, 2003.

  1. Eric Weiss

    Eric Weiss Guest

    I have an XML document that I want to use to create two HTML versions:
    one detailed and one a summary. The detailed output is straight forward
    to create, but the summary output that excludes the details is giving me
    trouble. The original XML file looks like:
    <PROJECTS>
    <PROJECT>
    This is a brief description.
    <DETAILS>
    There are a lot of details here that should not always be in the output
    html file.
    </DETAILS>
    There might be some more summary stuff here
    </PROJECT>
    </PROJECTS>

    So the XSLT file to create a summary looks something like:
    <HTML>
    <xsl:apply-templates select="PROJECT">
    </HTML>

    <xsl:template match="PROJECT">
    <xsl:value-of select="."/>
    </xsl:template>

    Is there any way to do this without adding a <SUMMARY> child to
    <PROJECT>? I would prefer not to do that because I am trying to come up
    with a very general approach that would allow for different amounts of
    information to appear in the detail.

    Thanks.

    Eric
    Eric Weiss, Jul 6, 2003
    #1
    1. Advertising

  2. Eric Weiss

    Eric Weiss Guest

    Thanks. That is just what I was looking for.

    Eric


    Dimitre Novatchev wrote:
    > The way to exclude only a certain node is the following:
    >
    > 1. Use the identity rule (template) as the first in the transformation.
    >
    > 2. Override it with a separate rule (template) for the node that must be
    > excluded.
    >
    > 3. To exclude the node the overriding template must be empty.
    >
    >
    > This gives us the following transformation:
    >
    >
    > <xsl:stylesheet version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    >
    > <xsl:eek:utput omit-xml-declaration="yes"/>
    >
    > <xsl:template match="@* | node()">
    > <xsl:copy>
    > <xsl:apply-templates select="@* | node()"/>
    > </xsl:copy>
    > </xsl:template>
    >
    > <xsl:template match="DETAILS"/>
    >
    > </xsl:stylesheet>
    >
    >
    > When applied on this source.xml:
    >
    > <PROJECTS>
    > <PROJECT>
    > This is a brief description.
    > <DETAILS>
    > There are a lot of details here that should not always be in the output
    > html file.
    > </DETAILS>
    > There might be some more summary stuff here
    > </PROJECT>
    > <PROJECT>
    > 2This is a brief description2.
    > <DETAILS>
    > 2There are a lot of details here that should not always be in the output
    > html file2.
    > </DETAILS>
    > 2There might be some more summary stuff here2
    > </PROJECT>
    > </PROJECTS>
    >
    > The wanted result is produced:
    >
    > <PROJECTS>
    > <PROJECT>
    > This is a brief description.
    >
    > There might be some more summary stuff here
    > </PROJECT>
    > <PROJECT>
    > 2This is a brief description2.
    >
    > 2There might be some more summary stuff here2
    > </PROJECT>
    > </PROJECTS>
    >
    >
    >
    >
    > =====
    > Cheers,
    >
    > Dimitre Novatchev.
    > http://fxsl.sourceforge.net/ -- the home of FXSL
    >
    >
    >
    >
    > "Eric Weiss" <> wrote in message
    > news:...
    >
    >>I have an XML document that I want to use to create two HTML versions:
    >>one detailed and one a summary. The detailed output is straight forward
    >>to create, but the summary output that excludes the details is giving me
    >>trouble. The original XML file looks like:
    >><PROJECTS>
    >><PROJECT>
    >>This is a brief description.
    >><DETAILS>
    >>There are a lot of details here that should not always be in the output
    >>html file.
    >></DETAILS>
    >>There might be some more summary stuff here
    >></PROJECT>
    >></PROJECTS>
    >>
    >>So the XSLT file to create a summary looks something like:
    >><HTML>
    >><xsl:apply-templates select="PROJECT">
    >></HTML>
    >>
    >><xsl:template match="PROJECT">
    >> <xsl:value-of select="."/>
    >></xsl:template>
    >>
    >>Is there any way to do this without adding a <SUMMARY> child to
    >><PROJECT>? I would prefer not to do that because I am trying to come up
    >>with a very general approach that would allow for different amounts of
    >>information to appear in the detail.
    >>
    >>Thanks.
    >>
    >>Eric
    >>

    >
    >
    >
    Eric Weiss, Jul 6, 2003
    #2
    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:
    395
  2. Jeff Rodriguez
    Replies:
    23
    Views:
    1,070
    David Schwartz
    Dec 9, 2003
  3. Satya Nanda Vel Arjunan
    Replies:
    1
    Views:
    917
    Thomas Heller
    May 5, 2004
  4. kimimaro
    Replies:
    4
    Views:
    286
    Barry Schwarz
    Nov 1, 2004
  5. Al-Burak
    Replies:
    6
    Views:
    287
    Al-Burak
    Dec 19, 2005
Loading...

Share This Page