XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> - XSL-fo and how to line feed th... (1)
-> + Houston we have a problem (2)
-> + XSL-FO PDF generation (2)
-> + StylusStudio - pick XSLT 1.0 b... (6)
-> - Stylus Studio 2010 debugging f... (1)
-> - Drop down menu List / Option M... (1)
-> - XML transformation using Java ... (1)
-> + i can't to find XSLT editor in... (2)
-> - Copy xml input as value of an ... (1)
-> - Remove Name space from the Tab... (1)
-> - CGI formatted URL with name/va... (1)
-> - Problem with counting (1)
-> + for-each loop is only returnin... (3)
-> - sort date but some dates may b... (1)
-> - Entity Conversion (1)
-> - How can I build an xml convert... (1)
-> + Little Help (2)
-> + how do I merge nodes to one sc... (2)
-> - beginner help xslt and xpath (1)
-> - Convert XML Feed to CSV/SQL/XL... (1)
-> - Working with text node. (1)
-> - No Topic (1)
-> - API for XSLT Converter for .NE... (1)
-> - Getting started (1)
-> + saxon sql extensions - mysql a... (2)
-> - How do I copy and create new e... (1)
-> + substring-before and sums (3)
-> + Parsing special characters in ... (2)
-> + Schema - Require attribute in ... (2)
-> - Edit existing XSL files when n... (1)
-> + How can I use one single XSLT ... (2)
-> - Default selection of value in ... (1)
-> - Problem with watermark in pdf ... (1)
-> + XSLT Parameter Values dialog n... (3)
-> + Value of File Name is not acce... (10)
-> - Need help with a complex table... (1)
-> - How to replace all nordic char... (1)
-> - XSLT java heap space error wit... (1)
-> - Table Overflow to next page (1)
-> - Using XSLT 2.0 to define custo... (1)
-> - "standalone" attribute and xs... (1)
-> + Standardizing IP addresses (2)
-> + Programmatically changing page... (6)
-> + Can Stylus generate XSLT if so... (5)
-> + Extraction based on NODE Name. (2)
-> + NO XSLT:WYSIWYG (2)
-> + determine condition at run tim... (2)
-> - How to reduce top margin in ev... (1)
-> + need help on xsl looping (4)
-> - Convert Symbol to Element (1)
-> + Separator -only- between field... (3)
-> + DocBook (9)
-> + First Occurance of Alphabet (2)
-> + XSL:Key and Document (2)
-> + Excel Macro using XSLT (2)
-> + Add missing element and attrib... (2)
-> + XSL: Stop Count at First Match (2)
-> + XSD to EDI (4)
-> + How to access data from nested... (2)
-> + Simple division of XML file (2)
-> - XML to Flat File (1)
-> + Dispalying data whith xsl:for ... (3)
-> - distinct nodes - into 3 column... (1)
-> + Newbie at XML (2)
-> + XSL Not Working (3)
-> + to draw table using xsl (2)
-> + Base64 decoder (5)
-> + How to create a hidden sheet u... (3)
-> + XML Reports (2)
-> + Copying image files from one d... (2)
-> + XML conversion to RSS (2)
-> + Inserting Image (2)
-> + Xml to Pdf using Xsl (2)
-> + Using a parameter (or similar)... (2)
-> + How to avoid creating empty xm... (2)
-> + how to read txt files in xml (2)
-> + Limit records to 4 per page. P... (4)
-> + XSLT Mapping Based on JDK5 (2)
-> + XML Mappin (2)
-> + Format Datetime with xslt (3)
-> + Cell border missing (2)
-> + XSL: Key (not matches) (5)
-> + Loop through each char in stri... (2)
-> + What is the best way to sum va... (3)
-> + xslt sort help (2)
-> + getting the count (2)
-> + XSL dynamic variables (5)
-> + XSL:Key use (3)
-> + Help With Updating Attributes ... (8)
-> + GETTING COUNT AND POSITION usi... (3)
-> - Hi Everyone !! (1)
-> + Graph Traversal (Keep track of... (2)
-> + XSL IF with sum (2)
-> + Param not incrementing (2)
-> + Iterating through value tags (3)
-> + URGENT :::: Remove the name sp... (2)
-> + Pass new param values to ASP O... (2)
-> + Detect Browser Version in XSL (2)
-> + xslt result-document (2)
-> + Unique nodes based on two attr... (3)
-- Previous [181-200] [201-220] [221-240] Next
+ XQuery Help and Discussion (2015)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
Ann Marie RubinSubject: merge contents of consecutive duplicate elements
Author: Ann Marie Rubin
Date: 18 Oct 2005 10:03 AM
Hello,

I have XML that can contain duplicate, consecutive elements with different contents, for example:

<info>
<para>text A </para>
<note>note A </note>
</info>
<info>
<para>text B</para>
<note>note B</note>
<para>text C</para>
</info>

How can I do the following in XSLT 1.0?

merge the contents of the duplicate elements into a single info element, for example:

<info>
<para>text A</para>
<note>note A</note>
<para>text B</para>
<note>note B</note>
<para>text C</para>
</info>

Thanks,

Ann Marie

Postnext
(Deleted User) Subject: merge contents of consecutive duplicate elements
Author: (Deleted User)
Date: 18 Oct 2005 11:41 AM
If you do want to generate single element to replace group of elements with the same name (and concatinate content) you can use something like this :

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="Key" match="/xml/*" use="local-name()"/>

<xsl:template match="/">
<xml>
<xsl:for-each select="/xml/*">
<xsl:if test="generate-id()= generate-id(key('Key',local-name())[1])">
<xsl:copy select=".">
<xsl:for-each select="key('Key',local-name())">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:copy>
</xsl:if>
</xsl:for-each>
</xml>
</xsl:template>
</xsl:stylesheet>

But from your example I can see that probably you do want to do different thing : just use single <info> as a root and collect all children of all <info> elements from original XML under this info. If this is tha case you can use following XSLT:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xml>
<info>
<xsl:for-each select="xml/info/*">
<xsl:copy-of select="."/>
</xsl:for-each>
</info>
</xml>
</xsl:template>
</xsl:stylesheet>

Postnext
Ann Marie RubinSubject: merge contents of consecutive duplicate elements
Author: Ann Marie Rubin
Date: 18 Oct 2005 01:54 PM
thanks for the suggestion, Yuriv.

Yes, I want to generate a single element to replace two consecutive info elements that are children of an overview element and have the same name (and concatinate content.) There will be no more than one pair of these info elements in each overview element. I don't want to generate a single element containing all duplicate elements.

For example, this code finds the info element that is a child of an overview element and whose next following sibling is also an info element.

<xsl:template match="overview/info[following-sibling::*[1][self::info]]" >

At this point, I'm stuck. How do I concatenate both elements?

thanks,

Ann Marie

Postnext
Ivan PedruzziSubject: merge contents of consecutive duplicate elements
Author: Ivan Pedruzzi
Date: 18 Oct 2005 03:53 PM
Hi Ann,

Assuming your input looks like this

<?xml version="1.0"?>
<overview>
<info>
<para>text A</para>
<note>note A</note>
</info>
<info>
<para>text A</para>
<note>note A</note>
<para>text B</para>
<note>note B</note>
<para>text C</para>
</info>
</overview>

applying the following

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
<xsl:apply-templates select="overview"/>
</xsl:template>

<xsl:template match="overview">
<xsl:copy>
<info>
<xsl:apply-templates select="*"/>
</info>
</xsl:copy>
</xsl:template>

<xsl:template match="info">
<xsl:apply-templates select="*"/>
</xsl:template>

<xsl:template match="*">
<xsl:variable name="current" select="."/>
<xsl:if test="not(../following-sibling::info[1]/*[. = $current])">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:template>

</xsl:stylesheet>



results in


<?xml version='1.0' ?>
<overview>
<info>
<para>text A</para>
<note>note A</note>
<para>text B</para>
<note>note B</note>
<para>text C</para>
</info>
</overview>


hope this helps
Ivan Pedruzzi
Stylus Studio Team

Postnext
Ann Marie RubinSubject: merge contents of consecutive duplicate elements
Author: Ann Marie Rubin
Date: 18 Oct 2005 09:07 PM
The info elements are still not merged. Can you see what the problem is? Note that I needed to add the <xsl:apply-templates select="@*|node()"/> statement in the match / template or I got no output at all.

Thanks,

Ann Marie

Here is the xml:

<?xml version="1.0"?>
<doctitle>
<prodtitle>prodtitle</prodtitle>
<title>title</title>
</doctitle>
<subtitle>subtitle</subtitle>
<copyright id="_1">
<para>paragraph</para>
</copyright>
<preface>
<purpose>
<info>
<para>paragraph</para>
</info>
</purpose>
<audience>
<info>
<para>paragraph</para>
</info>
</audience>
<organization>
<info>
<para>paragraph</para>
</info>
</organization>
<relateddocumentation>
<info>
<para>paragraph</para>
</info>
</relateddocumentation>
<boilerplate id="_2">
<concept id="_3">
<title>concept</title>
<overview>
<info>
<para>overview paragraph</para>
</info>
</overview>
<subconcept>
<title>subconcept</title>
<overview>
<info>
<para>overview paragraph A</para>
</info>
<info>
<para>overview paragraph B</para>
</info>
</overview>
<info>
<para>test</para>
</info>
</subconcept>
<minitask>
<title>minitask title</title>
<overview>
<info>
<para>minitask overview paragraph</para>
</info>
</overview>
<minitasksteps>
<minitaskstep>
<action>action</action>
</minitaskstep>
</minitasksteps>
</minitask>
</concept>
</boilerplate>
</preface>

<section solution="all" id="_7" htmlfilename="test">
<title>test</title>
</section>
</document>

Here is the stylesheet:

<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:key name="Key" match="info" use="local-name()"/>

<xsl:template match="/">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
<xsl:apply-templates select="overview"/>
</xsl:template>

<xsl:template match="overview">
<xsl:copy>
<info>
<xsl:apply-templates select="*"/>
</info>
</xsl:copy>
</xsl:template>

<xsl:template match="info">
<xsl:apply-templates select="*"/>
</xsl:template>

<xsl:template match="*">
<xsl:variable name="current" select="."/>
<xsl:if test="not(../following-sibling::info[1]/*[. = $current])">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:template>

<!-- Default Copy Statement. -->
<xsl:template match="@*|node()" priority="1">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:apply-templates />
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

Here is the output:

<?xml version="1.0" encoding="UTF-8"?><document language="en" product="ICM" documenttype="guide" softwareversion="1.0" dtdversion="2.8(0)">
<doctitle>
<prodtitle>prodtitle</prodtitle>
<title>title</title>
</doctitle>
<subtitle>subtitle</subtitle>
<copyright id="_1">
<para>paragraph</para>
</copyright>
<preface>
<purpose>
<info>
<para>paragraph</para>
</info>
</purpose>
<audience>
<info>
<para>paragraph</para>
</info>
</audience>
<organization>
<info>
<para>paragraph</para>
</info>
</organization>
<relateddocumentation>
<info>
<para>paragraph</para>
</info>
</relateddocumentation>
<boilerplate id="_2">
<concept id="_3">
<title>concept</title>
<overview>
<info>
<para>overview paragraph</para>
</info>
</overview>
<subconcept>
<title>subconcept</title>
<overview>
<info>
<para>overview paragraph A</para>
</info>
<info>
<para>overview paragraph B</para>
</info>
</overview>
<info>
<para>test</para>
</info>
</subconcept>
<minitask>
<title>minitask title</title>
<overview>
<info>
<para>minitask overview paragraph</para>
</info>
</overview>
<minitasksteps>
<minitaskstep>
<action>action</action>
</minitaskstep>
</minitasksteps>
</minitask>
</concept>
</boilerplate>
</preface>

<section solution="all" id="_7" htmlfilename="test">
<title>test</title>
</section>
</document>

Postnext
Ann Marie RubinSubject: merge contents of consecutive duplicate elements
Author: Ann Marie Rubin
Date: 18 Oct 2005 09:08 PM
The info elements are still not merged. Can you see what the problem is? Note that I needed to add the <xsl:apply-templates select="@*|node()"/> statement in the match / template or I got no output at all.

Thanks,

Ann Marie

Here is the xml:

<?xml version="1.0"?>
<doctitle>
<prodtitle>prodtitle</prodtitle>
<title>title</title>
</doctitle>
<subtitle>subtitle</subtitle>
<copyright id="_1">
<para>paragraph</para>
</copyright>
<preface>
<purpose>
<info>
<para>paragraph</para>
</info>
</purpose>
<audience>
<info>
<para>paragraph</para>
</info>
</audience>
<organization>
<info>
<para>paragraph</para>
</info>
</organization>
<relateddocumentation>
<info>
<para>paragraph</para>
</info>
</relateddocumentation>
<boilerplate id="_2">
<concept id="_3">
<title>concept</title>
<overview>
<info>
<para>overview paragraph</para>
</info>
</overview>
<subconcept>
<title>subconcept</title>
<overview>
<info>
<para>overview paragraph A</para>
</info>
<info>
<para>overview paragraph B</para>
</info>
</overview>
<info>
<para>test</para>
</info>
</subconcept>
<minitask>
<title>minitask title</title>
<overview>
<info>
<para>minitask overview paragraph</para>
</info>
</overview>
<minitasksteps>
<minitaskstep>
<action>action</action>
</minitaskstep>
</minitasksteps>
</minitask>
</concept>
</boilerplate>
</preface>

<section solution="all" id="_7" htmlfilename="test">
<title>test</title>
</section>
</document>

Here is the stylesheet:

<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:key name="Key" match="info" use="local-name()"/>

<xsl:template match="/">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
<xsl:apply-templates select="overview"/>
</xsl:template>

<xsl:template match="overview">
<xsl:copy>
<info>
<xsl:apply-templates select="*"/>
</info>
</xsl:copy>
</xsl:template>

<xsl:template match="info">
<xsl:apply-templates select="*"/>
</xsl:template>

<xsl:template match="*">
<xsl:variable name="current" select="."/>
<xsl:if test="not(../following-sibling::info[1]/*[. = $current])">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:template>

<!-- Default Copy Statement. -->
<xsl:template match="@*|node()" priority="1">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:apply-templates />
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

Here is the output:

<?xml version="1.0" encoding="UTF-8"?><document language="en" product="ICM" documenttype="guide" softwareversion="1.0" dtdversion="2.8(0)">
<doctitle>
<prodtitle>prodtitle</prodtitle>
<title>title</title>
</doctitle>
<subtitle>subtitle</subtitle>
<copyright id="_1">
<para>paragraph</para>
</copyright>
<preface>
<purpose>
<info>
<para>paragraph</para>
</info>
</purpose>
<audience>
<info>
<para>paragraph</para>
</info>
</audience>
<organization>
<info>
<para>paragraph</para>
</info>
</organization>
<relateddocumentation>
<info>
<para>paragraph</para>
</info>
</relateddocumentation>
<boilerplate id="_2">
<concept id="_3">
<title>concept</title>
<overview>
<info>
<para>overview paragraph</para>
</info>
</overview>
<subconcept>
<title>subconcept</title>
<overview>
<info>
<para>overview paragraph A</para>
</info>
<info>
<para>overview paragraph B</para>
</info>
</overview>
<info>
<para>test</para>
</info>
</subconcept>
<minitask>
<title>minitask title</title>
<overview>
<info>
<para>minitask overview paragraph</para>
</info>
</overview>
<minitasksteps>
<minitaskstep>
<action>action</action>
</minitaskstep>
</minitasksteps>
</minitask>
</concept>
</boilerplate>
</preface>

<section solution="all" id="_7" htmlfilename="test">
<title>test</title>
</section>
</document>

Postnext
(Deleted User) Subject: merge contents of consecutive duplicate elements
Author: (Deleted User)
Date: 19 Oct 2005 08:22 AM
If your task is to replace all <info> elements located under <overview> element with a single <info> element and concatinate children under this new <info> and you want to do this in cases a) and b) :

a) <overview>
<info/>
<other/>
<info/>
</overview>


and

b)
<overview>
<info/>
<info/>
<other/>
</overview>

then you can use this :

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
<xml>
<xsl:apply-templates select="descendant::overview"/>
</xml>
</xsl:template>

<xsl:template match="overview">
<info>
<xsl:for-each select="info/*">
<xsl:copy-of select="."/>
</xsl:for-each>
</info>
</xsl:template>

</xsl:stylesheet>

If you want to perform merge only in case b) extra check have to be added.

Postnext
Ann Marie RubinSubject: merge contents of consecutive duplicate elements
Author: Ann Marie Rubin
Date: 20 Oct 2005 10:03 PM
Hi Yuriv,

Thanks for your help. I hope you can give me some tips on how to do this.

How can I modify my stylesheet to handle this case:

Regards,

Ann Marie

input:

<concept>
<overview>
<info>
<para>A</para>
</info>
</overview>
<info>
<para>B</para>
</info>
</concept>

There are overview elements in other parts of the tree that don't want to change. I want to combine info element children of concept/overview with the info element that is the immediately following sibling of overview in a single info element.

desired output:

<concept>
<info>
<para>A</para>
<para>B</para>
</info>
</concept>

Postnext
Ivan PedruzziSubject: merge contents of consecutive duplicate elements
Author: Ivan Pedruzzi
Date: 19 Oct 2005 03:47 PM

In case you were looking to just merge the duplicates under overview/info and leave the rest as it is, take a look to the attached solution

hope this helps
Ivan Pedruzzi
Stylus Studio Team


Documentmerge-duplicates.xsl

Postnext
Ann Marie RubinSubject: merge contents of consecutive duplicate elements
Author: Ann Marie Rubin
Date: 20 Oct 2005 10:08 PM
thanks Ivan.

I need to merge the duplicate info elements under overview children of concept but not other info elements. See my reply to Yuriv. I'm going to try out this stylesheet and see if I can modify it to merge the info child of concept/overview with overview's following sibling info node.

that's the problem I need to solve now.

If you have any suggestions, I would greatly appreciate it.

thanks much,

Ann Marie

Postnext
(Deleted User) Subject: merge contents of consecutive duplicate elements
Author: (Deleted User)
Date: 21 Oct 2005 11:03 AM
Take a look at this example:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
<concept>
<info>
<xsl:apply-templates select="concept/overview/info/para | concept/info/para"/>
</info>
</concept>
</xsl:template>

<xsl:template match="para">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>

We can modify Ivan template to handle this case too, so you'll get original tree with info elements merged, not just sample case. But let's make sure first that we understand requirements correctly.
If you will post complete input XML with all possible cases and desired output XML we will try to come up with stylesheet.

Regards,

Yuriy

Postnext
Ann Marie RubinSubject: merge contents of consecutive duplicate elements
Author: Ann Marie Rubin
Date: 27 Oct 2005 01:02 PM
Hello Yuriy,

Sorry for the delay. I am attaching the input xml and desired output xml. I only want to merge the contents of subconcept/overview/info and the following-sibling info element of subconcept/overview. There are overview/info elements that are children of other elements, such as, minitask, that should be left alone.

Let me know if you have any questions about the requirements.

Regards,

Ann Marie

Postnext
Ann Marie RubinSubject: merge contents of consecutive duplicate elements
Author: Ann Marie Rubin
Date: 27 Oct 2005 01:12 PM
Hello Yuriy,

Sorry for the delay. I am attaching the input xml and desired output xml. I want to remove overview children of subconcept and merge the contents of subconcept/overview/info and the following-sibling info element of subconcept/overview. There are overview/info elements that are children of other elements, such as, minitask, that should be left alone.

For example, the following input:
<subconcept id="_8">
<title>concept</title>
<overview>
<info>
<para>para A</para>
</info>
</overview>
<info>
<para>para B</para>
</info>
</subconcept>

should be changed to:
<subconcept id="_8">
<title>subconcept</title>
<info>
<para>para 1</para>
<para>para 2</para>
</info>
</subconcept>
Let me know if you have any questions about the requirements.

Regards,

Ann Marie

Postnext
(Deleted User) Subject: merge contents of consecutive duplicate elements
Author: (Deleted User)
Date: 27 Oct 2005 03:06 PM
You can change Ivan XSLT (published in this thread) :

change :


<xsl:template match="overview">

into :

<xsl:template match="subconcept/overview">

and you'll get following output:


<?xml version='1.0' ?>
<document>
<doctitle>
<prodtitle>prodtitle</prodtitle>
<title>title</title>
</doctitle>
<subtitle>subtitle</subtitle>
<copyright id="_1">
<para>paragraph</para>
</copyright>
<preface>
<purpose>
<info>
<para>paragraph</para>
</info>
</purpose>
<audience>
<info>
<para>paragraph</para>
</info>
</audience>
<organization>
<info>
<para>paragraph</para>
</info>
</organization>
<relateddocumentation>
<info>
<para>paragraph</para>
</info>
</relateddocumentation>
<boilerplate id="_2">
<concept id="_3">
<title>concept</title>
<overview>
<info>
<para>overview paragraph</para>
</info>
</overview>
<subconcept>
<title>subconcept</title>
<overview><info><para>overview paragraph A</para><para>overview paragraph B</para></info></overview>
<info>
<para>test</para>
</info>
</subconcept>
<minitask>
<title>minitask title</title>
<overview>
<info>
<para>minitask overview paragraph</para>
</info>
</overview>
<minitasksteps>
<minitaskstep>
<action>action</action>
</minitaskstep>
</minitasksteps>
</minitask>
</concept>
</boilerplate>
</preface>

<section solution="all" id="_7" htmlfilename="test">
<title>test</title>
</section>
</document>


where


<subconcept>
<title>subconcept</title>
<overview>
<info>
<para>overview paragraph A</para>
<para>overview paragraph B</para>
</info>
</overview>

2 <info> tags replaced with single <info>
all <info> children are merged (<para>)
and all this happens only if <overview> is direct child of <subconcept>


Hope this will help

Postnext
Ann Marie RubinSubject: merge contents of consecutive duplicate elements
Author: Ann Marie Rubin
Date: 27 Oct 2005 03:25 PM
Thank you very much. I'll give it a try.

Postnext
Ann Marie RubinSubject: merge contents of consecutive duplicate elements
Author: Ann Marie Rubin
Date: 28 Oct 2005 02:16 PM
Hi,

I ran Ivan's merge_duplicates.xsl with template match=subconcept/overview. The info elements are still not merged. Did I miss something?

thanks,

Ann Marie


Unknownmerge_out.xml

Postnext
(Deleted User) Subject: merge contents of consecutive duplicate elements
Author: (Deleted User)
Date: 28 Oct 2005 02:46 PM
Here is input file:

<?xml version="1.0"?>
<document>
<doctitle>
<prodtitle>prodtitle</prodtitle>
<title>title</title>
</doctitle>
<subtitle>subtitle</subtitle>
<copyright id="_1">
<para>paragraph</para>
</copyright>
<preface>
<purpose>
<info>
<para>paragraph</para>
</info>
</purpose>
<audience>
<info>
<para>paragraph</para>
</info>
</audience>
<organization>
<info>
<para>paragraph</para>
</info>
</organization>
<relateddocumentation>
<info>
<para>paragraph</para>
</info>
</relateddocumentation>
<boilerplate id="_2">
<concept id="_3">
<title>concept</title>
<overview>
<info>
<para>overview paragraph</para>
</info>
</overview>
<subconcept>
<title>subconcept</title>
<overview>
<info>
<para>overview paragraph A</para>
</info>
<info>
<para>overview paragraph B</para>
</info>
</overview>
<info>
<para>test</para>
</info>
</subconcept>
<minitask>
<title>minitask title</title>
<overview>
<info>
<para>minitask overview paragraph</para>
</info>
</overview>
<minitasksteps>
<minitaskstep>
<action>action</action>
</minitaskstep>
</minitasksteps>
</minitask>
</concept>
</boilerplate>
</preface>

<section solution="all" id="_7" htmlfilename="test">
<title>test</title>
</section>
</document>

Here is XSLT:


<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="subconcept/overview">
<xsl:copy>
<info>
<xsl:apply-templates select="@*|*" mode="merge"/>
</info>
</xsl:copy>
</xsl:template>

<xsl:template match="info" mode="merge">
<xsl:apply-templates select="@*|*" mode="merge"/>
</xsl:template>

<xsl:template match="*" mode="merge">
<xsl:variable name="current" select="."/>
<xsl:if test="not(../following-sibling::info[1]/*[. = $current])">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:if>
</xsl:template>

<xsl:template match="text()">
<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="@*|*">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

Here is output file:



<?xml version='1.0' ?>
<document>
<doctitle>
<prodtitle>prodtitle</prodtitle>
<title>title</title>
</doctitle>
<subtitle>subtitle</subtitle>
<copyright id="_1">
<para>paragraph</para>
</copyright>
<preface>
<purpose>
<info>
<para>paragraph</para>
</info>
</purpose>
<audience>
<info>
<para>paragraph</para>
</info>
</audience>
<organization>
<info>
<para>paragraph</para>
</info>
</organization>
<relateddocumentation>
<info>
<para>paragraph</para>
</info>
</relateddocumentation>
<boilerplate id="_2">
<concept id="_3">
<title>concept</title>
<overview>
<info>
<para>overview paragraph</para>
</info>
</overview>
<subconcept>
<title>subconcept</title>
<overview><info><para>overview paragraph A</para><para>overview paragraph B</para></info></overview>
<info>
<para>test</para>
</info>
</subconcept>
<minitask>
<title>minitask title</title>
<overview>
<info>
<para>minitask overview paragraph</para>
</info>
</overview>
<minitasksteps>
<minitaskstep>
<action>action</action>
</minitaskstep>
</minitasksteps>
</minitask>
</concept>
</boilerplate>
</preface>

<section solution="all" id="_7" htmlfilename="test">
<title>test</title>
</section>
</document>


Take a look how in :

<subconcept>
<title>subconcept</title>
<overview>
<info>
<para>overview paragraph A</para>
</info>
<info>
<para>overview paragraph B</para>
</info>
</overview>
<info>
<para>test</para>
</info>
</subconcept>

2 <overview> child <info> elements were replaced with one <info> element with merged children :


<subconcept>
<title>subconcept</title>
<overview>
<info>
<para>overview paragraph A</para>
<para>overview paragraph B</para>
</info>
</overview>
<info>

Posttop
Ann Marie RubinSubject: merge contents of consecutive duplicate elements
Author: Ann Marie Rubin
Date: 28 Oct 2005 03:09 PM
Ah. This stylesheet merges para A and B given this xml input:
<overview>
<info>
<para>para A</para>
</info>
<info>
<para>para B</para>
</info>

</overview>
<info>
<para>para C</para>
</info>

To get this xml output:
<info>
<para>para A</para>
<para>para B</para>
</info>
<info>
<para>para C</para>
</info>


But, I'm trying to remove the overview element and merge para A and para C in this xml input :


<overview>
<info>
<para>para A</para>
</info>

</overview>
<info>
<para>para C</para>
</info>


To get this xml output:
<info>
<para>para A</para>
<para>para C</para>

</info>


see my attached xml input.

thanks,

Ann Marie


Unknowntest_multiconcept.xml

   
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.