473,509 Members | 2,508 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Excluding Child for Repurposing with XML and XSLT

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

Jul 20 '05 #1
1 1957
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:output 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" <ew****@winchendon.com> wrote in message
news:3F**************@winchendon.com...
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



Jul 20 '05 #2

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

Similar topics

1
2413
by: Terry Chilvers | last post by:
In XSLT I want to select elements and output the value of a particular attribute. However I don't want to process the element if it doesn't contain this attribute. I'm using this to generate some...
5
6472
by: Tim | last post by:
I've been working on this for over a week now, and just can't get this figured out. Hoping one of you gurus can help me out here. I have an xml data island that I'm representing on an htm page as...
3
2220
by: William Krick | last post by:
Given this XML <parent> <child name="billy"> <child name="sue"> </parent> I can use this to process each child... <xsl:for-each select="child">
4
7708
by: Samuel R. Neff | last post by:
I'm writing an xslt in vs.net 2003 and in order to get intellisense on the html content I added the default namespace declaration xmlns="http://schemas.microsoft.com/intellisense/ie5". However,...
4
2897
by: patrizio.trinchini | last post by:
Hi all, I'm new to XSLT and maybe my problem have a very trivial answer, but I need an expert that point me in the right direction. What I would obtain is to remove all the elements that have a...
1
1807
by: renfrochris | last post by:
I'm having difficulty finding the correct syntax that will allow me to select a group of invoices based on the total of an amount column located in its line items. Below are simplified examples of...
3
5708
by: gregmcmullinjr | last post by:
Hi All, I would like to use XSLT to replace all <unodes that are children of a <bnode with a new <headingnode. Also, if the <bnode has no other children than remove it as well. For example: ...
4
4400
by: grbeal | last post by:
How do I test for a child element with xsl if condition? We have a vendor application that outputs an XML file containing records of School Closings due to inclement weather. That XML file gets...
2
6380
by: ofuuzo1 | last post by:
Hei, I have the following xml file and I have tried to write xslt to extract only the values of the first "record" node. It does not work. I need some help. I used ---- to represent indent. ...
0
7410
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...
1
7067
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7505
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...
0
5650
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4729
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...
0
3215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1570
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 ...
1
774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.