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

RE: value-of select - then multiply : For X3D

Subject: RE: value-of select - then multiply : For X3D
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 18 Jun 2008 14:04:22 +0100
RE:  value-of select - then multiply : For X3D
Let's try to be more precise:

> add 5 if there is a previous record with the same value 

By "record" I assume you mean a <work> element?

By "value" do you mean a <Work_Location_longitude> value? Or the combination
of longitude and latitude? Or something else?

By "previous" do you mean any previous <work> element, or must the elements
with the same value be adjacent?

Subject to these provisos, it's something like this:

<xsl:template match="work">
  <Group>
    <Transform>
      <xsl:attribute name="translation">
        <xsl:apply-templates select="Work_Location_longitude"/>
        <xsl:text> </xsl:text>
        <xsl:apply-templates select="Work_Location_latitude"/>
        <xsl:text> </xsl:text>
        <xsl:apply-templates select="Work_Year"/>
        <xsl:text> </xsl:text>
      </xsl:attribute>
      ...
</xsl:template>

<xsl:template
match="Work_Location_longitude[../preceding-sibling::work/Work_Location_long
itude[. = current()]]">
  <xsl:value-of select=". - 1.4 + 5"/>
</xsl:template>

<xsl:template match="Work_Location_longitude">
  <xsl:value-of select=". - 1.4"/>
</xsl:template>

etc.


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



> -----Original Message-----
> From: j milo taylor [mailto:milo@xxxxxxxxxx] 
> Sent: 18 June 2008 12:54
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  value-of select - then multiply : For X3D
> 
> Sorry for not being clear.
> I'm working on a XSLT for X3D, and this node deals with x,y,z 
> co-ordinates within such a 3d world, derived from 
> <Work_Location_longitude>, <Work_Location_latitude>, and 
> <Work_Year> respectively - each of which are elements in the 
> XML source file.
> 
> Here's an edited version of the source XML:
> 
> /////
> 
> <?xml version="1.0" encoding="iso-8859-1" ?> <?xml-stylesheet 
> type="text/xsl" href="X3D-XSLT_Work_Year.xsl"?> <works>
>     <work>
>         <Work_Year>1981</Work_Year>
>         <Work_Name>Rainfall at Launching Place</Work_Name>
>         <Work_Location>Australia</Work_Location>
>         <Work_Location_longitude>133</Work_Location_longitude>
>         <Work_Location_latitude>-27</Work_Location_latitude>  
>     </work>
>      <work>
>         <Work_Year>1981</Work_Year>  
>         <Work_Name>A Walk Through the City</Work_Name>
>         <Work_Location>Canada</Work_Location>
>         <Work_Location_longitude>-95</Work_Location_longitude>
>         <Work_Location_latitude>60</Work_Location_latitude>
>     </work>
>      <work>
>         <Work_Year>1981</Work_Year>     
>         <Work_Name>Five Silent Studies</Work_Name>    
>         <Work_Location>Canada</Work_Location>
>         <Work_Location_longitude>-95</Work_Location_longitude>
>         <Work_Location_latitude>60</Work_Location_latitude>
>     </work>
> 
> etc
> etc
> 
> <works>
> /////
> 
> I want to get the <Work_Location_longitude> values for each 
> record, -1.4 from this, and if there are previous records, 
> offset each of the subsequent results by 5. This will 
> determine the x value of the node position.
> 
> Similarly,
> 
> I want to get the <Work_Location_latitude> values for each 
> record, -2.2 from this, and if there are previous records, 
> offset each of the subsequent results by 5. This will 
> determine the y value of the node position.
> 
> Here's the XSLT (shortened version)
> 
> /////
> 
> <?xml version="1.0" encoding="UTF-8"?>
> 
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output media-type="model/x3d=xml" 
> doctype-system="http://www.web3d.org/specifications/x3d-3.2.dtd" 
> method="xml" encoding="UTF-8" indent="yes" 
> omit-xml-declaration="yes"/>
> 
>     <xsl:template match="/">
>        
>         <X3D profile="Immersive">&#10;
> 
>             <head>&#10;<title/></head>
>                 <Scene>
>                      <xsl:apply-templates/>
>                 </Scene>
>         </X3D>
> 
>     </xsl:template>
>     <xsl:template match="works">
>        
> <Group>
>   <xsl:for-each select="work">
>         <Group>
> 
>            <Transform  translation='0 0 0'> /<!-- i.e the 
> x,y,z co-ords for the node>/
> 
> <xsl:attribute name="translation">
> <xsl:value-of select="Work_Location_longitude"/>/ <!-- get 
> this value-of select,  -1.4, and add 5 if there is a previous 
> record with the same value value-of select 
> "Work_Location_longitude">/ <xsl:value-of 
> select="Work_Location_latitude"/>/<!-- get this value-of 
> select, -2.2, and add 5 if there is a previous record with 
> the same value-of select "Work_Location_latitude">/ 
> <xsl:value-of select="Work_Year div 10"/></xsl:attribute> 
> 
>                <Shape>
>                     <Appearance>     
>                      <Material />
>                     </Appearance>
> <xsl:element name="Text"><xsl:attribute name="string"> 
> <xsl:value-of select="Work_Year"/> </xsl:attribute> </xsl:element>
>                 </Shape>
>         </Transform> 
>         </Group> 
>     </xsl:for-each>
> </Group>   
> 
> etc
> etc
> etc
> 
> </xsl:template>
> 
> </xsl:stylesheet>
> 
> /////
> 
> And the output i want would be something like this:
> 
> /////
> 
> <!DOCTYPE X3D SYSTEM 
> "http://www.web3d.org/specifications/x3d-3.2.dtd">
> <X3D profile="Immersive">
> <head>
> <title/>
> </head>
> <Scene>
> <Group>
> 
> <Group>
> <Transform translation="*131.6 -29.2 198.1*"> /<!-- i.e 
> longitude -1.4, latitude -2.2, year / 10>/ <Shape> 
> <Appearance> <Material/> </Appearance> <Text 
> string="&quot;Rainfall at Launching Place&quot;"></Text>
> <!-- Text string="Australia"></Text> --> </Shape> 
> </Transform> </Group>
> 
> <Group>
> <Transform translation="*-93.6 57.8 198.1*"> /<!-- i.e 
> longitude -1.4, latitude -2.2, year / 10>/ <Shape> 
> <Appearance> <Material/> </Appearance> <Text string="A Walk 
> Through the City"></Text>
> <!-- <Text string="Canada"></Text> -->
> </Shape>
> </Transform>
> </Group>
> 
> <Group>
> <Transform translation="*-88.6 62.8 198.1*"> /<!-- i.e longitude -1.4 
> +5, latitude -2.2 +5, year / 10>/
> <Shape>
> <Appearance>
> <Material/>
> </Appearance>
> <Text string="Five Silent Studies"></Text>
> <!-- <Text string="Canada"></Text> -->
> </Shape>
> </Transform>
> </Group>
> 
> etc
> etc
> 
> </Group>
> </Scene>
> </X3D>
> 
> ////
> 
> Can anyone shed any light on this?
> 
> Best Regards
> Milo

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.