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)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
Doug PotterSubject: PRoblems with XML-XML structure conversion
Author: Doug Potter
Date: 06 Aug 2002 10:39 PM
Actually the structure is OK, it's the repetitions that are causing me problems. What I've got for source data is data that was originally header-detail but got flattened when exported to XML.

root
  hd1  1   /hd1
  hd2  A   /hd2
  ln1  10  /ln1
  ln2  10A /ln2
/root
root
  hd1  1   /hd1
  hd2  A   /hd2
  ln1  20  /ln1
  ln2  1A  /ln2
/root
root
  hd1  2   /hd1
  hd2  B   /hd2
  ln1  10  /ln1
  ln2  2A  /ln2
/root

Note that the first two roots have the same h1 and h2 data.

What I need is something like:

root
  hd
    hd1  1   /hd1
    hd2  A   /hd2
  /hd
  ln
    ln1  10   /ln1
    ln2  10A  /ln2
  /ln
  ln
    ln1  20   /ln1
    ln2  1A   /ln2
  /ln
/root
root
  hd
    hd1  2   /hd1
    hd2  B   /hd2
  hd
  ln
    ln1  10  /ln1
    ln2  2A  /ln2
  ln
/root



But what I am getting is:

root
  hd
    hd1  1   /hd1
    hd2  A   /hd2
  /hd
  ln
    ln1  10   /ln1
    ln2  10A  /ln2
  /ln
/root
root
  hd
    hd1  1   /hd1
    hd2  A   /hd2
  /hd
  ln
    ln1  20  /ln1
    ln2  1A  /ln2
  /ln
/root
root
  hd
    hd1  2   /hd1
    hd2  B   /hd2
  /hd
  ln
    ln1  10  /ln1
    ln2  2A  /ln2
  /ln
/root

If there was a xsl:for-each-unique select="root/h1" available, that might work, but that doesn't exist.

Any help would be appreciated.

Thanks

Doug

Posttop
Ivan PedruzziSubject: RE: PRoblems with XML-XML structure conversion
Author: Ivan Pedruzzi
Date: 07 Aug 2002 03:38 AM

I could not exaclty follow the logic of your grouping example
Try to play with the following solution

{?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" indent="yes"/}
{xsl:template match="/"}
{r}
{xsl:for-each select="r/root"}
{xsl:choose}
{xsl:when test="(starts-with(name(*[1]), 'hd') and
not(*[1] = following-sibling::root/descendant::*)) or
not(starts-with(name(*[1]), 'hd'))"}
{root}
{xsl:call-template name="for-each-group"}
{xsl:with-param name="prefix" select="'hd'"/}
{/xsl:call-template}
{xsl:call-template name="for-each-group"}
{xsl:with-param name="prefix" select="'ln'"/}
{/xsl:call-template}
{/root}
{/xsl:when}
{/xsl:choose}
{/xsl:for-each}
{/r}
{/xsl:template}

{xsl:template name="for-each-group"}
{xsl:param name="prefix"/}
{xsl:param name="group"/}
{xsl:variable name="set" select="descendant::*[starts-with(name(),
$prefix)]"/}
{xsl:if test="$set"}
{xsl:element name="{$prefix}"}
{xsl:for-each select="$set"}
{xsl:copy-of select="."/}
{/xsl:for-each}
{/xsl:element}
{/xsl:if}
{/xsl:template}
{/xsl:stylesheet}


Ivan


> -----Original Message-----
> From: stylus-studio-xslt Listmanager [mailto:listmanager]
> Sent: Tuesday, August 06, 2002 10:53 PM
> To: Recipients of 'stylus-studio-xslt' suppressed
> Subject: PRoblems with XML-XML structure conversion
>
>
> From: "Doug Potter"
>
> Actually the structure is OK, it's the repetitions that are
> causing me problems. What I've got for source data is data
> that was originally header-detail but got flattened when
> exported to XML.
>
> root
> hd1 1 /hd1
> hd2 A /hd2
> ln1 10 /ln1
> ln2 10A /ln2
> /root
> root
> hd1 1 /hd1
> hd2 A /hd2
> ln1 20 /ln1
> ln2 1A /ln2
> /root
> root
> hd1 2 /hd1
> hd2 B /hd2
> ln1 10 /ln1
> ln2 2A /ln2
> /root
>
> Note that the first two roots have the same h1 and h2 data.
>
> What I need is something like:
>
> root
> hd
> hd1 1 /hd1
> hd2 A /hd2
> /hd
> ln
> ln1 10 /ln1
> ln2 10A /ln2
> /ln
> ln
> ln1 20 /ln1
> ln2 1A /ln2
> /ln
> /root
> root
> hd
> hd1 2 /hd1
> hd2 B /hd2
> hd
> ln
> ln1 10 /ln1
> ln2 2A /ln2
> ln
> /root
>
>
>
> But what I am getting is:
>
> root
> hd
> hd1 1 /hd1
> hd2 A /hd2
> /hd
> ln
> ln1 10 /ln1
> ln2 10A /ln2
> /ln
> /root
> root
> hd
> hd1 1 /hd1
> hd2 A /hd2
> /hd
> ln
> ln1 20 /ln1
> ln2 1A /ln2
> /ln
> /root
> root
> hd
> hd1 2 /hd1
> hd2 B /hd2
> /hd
> ln
> ln1 10 /ln1
> ln2 2A /ln2
> /ln
> /root
>
> If there was a xsl:for-each-unique select="root/h1"
> available, that might work, but that doesn't exist.
>
> Any help would be appreciated.
>
> Thanks
>
> Doug
>
>
>
> To reply: mailto:stylus-studio-xslt.5435@edn.exln.com
> To start a new topic: mailto:stylus-studio-xslt@edn.exln.com
> To login: http://edn.exln.com/~SSDN
>
>

   
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.