[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: complex numbering problem

Subject: RE: complex numbering problem
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 12 Dec 2008 16:03:28 -0000
RE:  complex numbering problem
It looks to me like this:

<xsl:for-each select="//event">
  <xsl:sort select="@start" data-type="number"/>
  <time_slot time_slot_id="ts{position()}" time_value="{@start}"/>
</xsl:for-each>

Or have I missed something?

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Alexander Koenig [mailto:Alexander.Koenig@xxxxxx] 
> Sent: 12 December 2008 15:53
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  complex numbering problem
> 
> Hi all,
> 
> I'm fairly new to XSL but after a couple of hours of googling 
> and thinking about how to structure my xsl file differently I 
> came here in the hope that someone can help me not using 
> saxon:assign (I already learned that this would be a bad 
> thing - but to be honest, I also cannot get it to work with 
> my Oxygen 9.3 ;-)
> 
> I'm using Oxygen 9.3 under SuSE Linux 10.0. XSL 1.0, Saxon 6.5.5
> 
> The problem is as follows: I want to transform one kind of 
> XML files into another kind using XSLT.
> 
> This is how (the relevant part of) my source file looks like:
> 
> <root>
> <layer l-id="l01">
> <meta m-id="m01">
> <desc><name>layer-interpretation</name><val>abc</val></desc>
> <desc><name>layer-type</name><val>some_type</val></desc>
> </meta>
> <event e-id="l01-001" start="0" end="17.499806"/> <event 
> e-id="l01-002" start="17.499806" end="17.524455">XYZ</event> 
> <event e-id="l01-003" start="17.524455" 
> end="113.487545">XYZ</event> <event e-id="l01-004" 
> start="113.487545" end="113.554857">XYZ</event> <event 
> e-id="l01-005" start="113.554857" end="113.94197">XYZ</event> 
> <event e-id="l01-006" start="113.94197" 
> end="114.1085">XYZ</event> </layer> <layer l-id="l02"> <meta 
> m-id="m02"> 
> <desc><name>layer-interpretation</name><val>xyz</val></desc>
> <desc><name>layer-type</name><val>some_other_type</val></desc>
> </meta>
> <event e-id="l02-001" start="0" end="17.7997">XYZ</event> 
> <event e-id="l02-002" start="17.7997" 
> end="112.409813">XYZ</event> <event e-id="l02-003" 
> start="112.409813" end="112.763921">XYZ</event> <event 
> e-id="l02-004" start="112.763921" 
> end="113.570947">XYZ</event> </layer> <!--some more layers--> </root>
> 
> This is how I want my target file to look like:
> 
> <time_order>
>     <time_slot time_slot_id="ts1" time_value="0"/>
>     <time_slot time_slot_id="ts2" time_value="0"/>
>     <time_slot time_slot_id="ts3" time_value="17.499806"/>
>     <time_slot time_slot_id="ts4" time_value="17.524455"/>
>     <time_slot time_slot_id="ts5" time_value="17.7997"/>
>     <time_slot time_slot_id="ts6" time_value="112.409813"/>
>     <time_slot time_slot_id="ts7" time_value="112.763921"/>
>     <time_slot time_slot_id="ts8" time_value="113.487545"/>
>     <time_slot time_slot_id="ts9" time_value="113.554857"/>
>     <time_slot time_slot_id="ts10" time_value="113.570947"/>
>     <time_slot time_slot_id="ts11" time_value="113.94197"/>
>     <time_slot time_slot_id="ts12" time_value="114.1085"/> 
> </time_order>
> 
> That means, I want every time index (even duplicates, because 
> I need them later on) in a separate time_slot element. The 
> time_slot elements should be sorted by the time_value in 
> ascending order and should get a unique id, also in ascending 
> order. I just cannot get the XSL structured in such a way 
> that both attributes are in order. It's always one or the 
> other, but never both. Or when I get both in order, I have 
> duplicate time_slot_id's instead.
> 
> My latest attempt looks like this:
> 
> <xsl:template match="event" mode="timeslots">
>     <time_slot>
>         <xsl:attribute name="time_slot_id">
>             <xsl:text>ts</xsl:text>
>             <xsl:number level="any" value="position()"/>
>         </xsl:attribute>
>         <xsl:attribute name="time_value">
>             <xsl:value-of select="@start"/>
>         </xsl:attribute>
>     </time_slot>
>     <xsl:if test="count(following-sibling::event)=0">
>         <time_slot>
>             <xsl:attribute name="time_slot_id">
>                 <xsl:text>ts</xsl:text>
>                 <xsl:number level="any" value="position()"/>
>             </xsl:attribute>
>             <xsl:attribute name="time_value">
>                 <xsl:value-of select="@end"/>
>             </xsl:attribute>
>         </time_slot>
>     </xsl:if>
> </xsl:template>
> 
> With this, both attributes are (almost, but not quite - why?) 
> in order, but I get duplicate IDs for the "end" attributes. 
> The result looks like
> this:
> 
> <time_order>
> ...
> <time_slot time_slot_id="ts1727" time_value="113.487545"/> 
> <time_slot time_slot_id="ts1728" time_value="113.554857"/> 
> <time_slot time_slot_id="ts1729" time_value="113.570521"/> 
> <time_slot time_slot_id="ts1729" 
> time_value="114.10741400000001"/> <time_slot 
> time_slot_id="ts1730" time_value="113.791077"/> <time_slot 
> time_slot_id="ts1730" time_value="114.10859000000001"/> 
> <time_slot time_slot_id="ts1731" 
> time_value="113.94197699999999"/> <time_slot 
> time_slot_id="ts1731" time_value="114.10859000000001"/> </time_order>
> 
> The only idea I have to fix this, is a variable which I 
> increase every time I enter the if block and which is added 
> to position() to form the ID. But XSL has no variables and so 
> I'm kind of stuck.
> 
> I hope one of the XSL experts out there can help me.
> 
> kind regards
> Alex

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.