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
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext 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
>
>

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
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.