Excluding Child for Repurposing with XML and XSLT

Excluding Child for Repurposing with XML and XSLT

Post by Eric Weis » Tue, 08 Jul 2003 01:35:12



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

 
 
 

Excluding Child for Repurposing with XML and XSLT

Post by Dimitre Novatche » Tue, 08 Jul 2003 02:30:45


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:output omit-xml-declaration="yes"/>


    <xsl:copy>

    </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


Quote:> 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


 
 
 

Excluding Child for Repurposing with XML and XSLT

Post by Eric Weis » Tue, 08 Jul 2003 02:35:18


Thanks.  That is just what I was looking for.

Eric


> 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:output omit-xml-declaration="yes"/>


>     <xsl:copy>

>     </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



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

 
 
 

1. Excluding a child node with XPath

I have the following node, which can occur in 2 different situations:

1)

<title>
Average Joe
<birthdate>1959</birthdate>
<deathdate>1985</deathdate>
</title>

2)
<title>
<emph render="bold">Average Joe</emph>
<birthdate>1959</birthdate>
<deathdate>1985</deathdate>
</title>

I want to use XPath to only "extract" the string "Average Joe." So I want to
exclude the <birthdate> and <deathdate> child nodes from the <title> node.
Is this possible?

For situation 1), I can use text() function, but I got stuck when I faced
with situation 2).

2. fast switched tunneling?

3. XSLT - Using When test on Child node - One and Only One Child

4. Ground Start Trunks (was Answer Supervision)

5. Placing UNIX files in long raw columns

6. Copy source document and exclude nodes with xslt?

7. Archie McLeod III

8. Repurposing

9. XSL or XPath problem: pick child based upon it's children??

10. Child Nodes's Child Node creation

11. Counting Children of Children

12. childs.item(0) != childs.item(0) ?!?