Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSL, select on one attribute, get value of another

Reply
Thread Tools

XSL, select on one attribute, get value of another

 
 
cching@mqsoftware.com
Guest
Posts: n/a
 
      09-19-2005
Hi,

I'm trying to turn this:

<Component>
<Properties>
<Property Name="X" Value="200" />
<Property Name="Y" Value="200" />
<Property Name="Width" Value="100" />
<Property Name="Height" Value="100" />
... other properties ...
</Properties>
</Component>

into this:

<div style="position: absolute; left: 200px; top: 200px; height: 100px;
width: 100px;">Blah</div>

I know how to find the nodes individually, e.g.:

<xsl:template match="Properties/Property[@Name='X']">
X: <xsl:value-of select="@Value" /> <br />
</xsl:template>

<xsl:template match="Properties/Property[@Name='Y']">
<xsl:variable name="Y" select="@Value" />
Y: <xsl:value-of select="@Value" /> <br />
</xsl:template>

but how can I do it for all of them and feed them into the div
attributes? I'm sure I'm missing something very fundamental and am
going to have an aha! experience if someone can help me figure this
out. Thanks in advance!

Cheers,
Craig

 
Reply With Quote
 
 
 
 
Joris Gillis
Guest
Posts: n/a
 
      09-19-2005
Hi,

On Mon, 19 Sep 2005 17:27:40 +0200, <(E-Mail Removed)> wrote:

> I'm trying to turn this:
><Component>
> <Properties>
> <Property Name="X" Value="200" />
> <Property Name="Y" Value="200" />
> <Property Name="Width" Value="100" />
> <Property Name="Height" Value="100" />
> ... other properties ...
> </Properties>
> </Component>
>into this:
><div style="position: absolute; left: 200px; top: 200px; height: 100px;
> width: 100px;">Blah</div>


There are lots of methods to do this. It's always best to look for a generic solution. Example:

<xsl:stylesheet version="1.0" xmlnssl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="myvar"
xmlns:myvar="myvariables">
<xslutput method="xml" indent="yes"/>

<myvar:map xmlns="">
<group unit="px">
<item name="X">left</item>
<item name="Y">top</item>
<item name="Height">height</item>
<item name="Width">width</item>
</group>
<group>
<item name="Colour">color</item>
</group>
</myvar:map>

<xsl:variable name="items" select="document('')/xsl:stylesheet/myvar:map//item"/>

<xsl:template match="Component">
<div>
<xsl:apply-templates select="Properties"/>
<xsl:apply-templates select="*[not(self:roperties)]"/>
</div>
</xsl:template>

<xsl:template match="Properties">
<xsl:attribute name="style">
<xsl:apply-templates select="Property"/>
</xsl:attribute>
</xsl:template>

<xsl:template match="Property">
<xsl:value-of select="$items[@name=current()/@Name]"/>
<xsl:text>: </xsl:text>
<xsl:value-of select="@Value"/>
<xsl:value-of select="$items[@name=current()/@Name]/ancestor-or-self::*/@unit[last()]"/>
<xsl:text>;</xsl:text>
</xsl:template>

</xsl:stylesheet>

--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
restrict the value of one child based on value from another child leon XML 0 09-27-2005 03:32 PM
Selection from One SELECT changes selected option of another SELECT? J. Hall HTML 2 04-21-2004 05:36 PM
select of select box will select multiple in another box palmiere Javascript 1 02-09-2004 01:11 PM
Transferring value from one select box to another Raghuram Banda Javascript 1 09-24-2003 07:27 AM
Passing value from one script on one page to another script on another page. Robert Cohen ASP General 3 07-15-2003 01:46 PM



Advertisments