473,394 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

XSL, select on one attribute, get value of another

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

Sep 19 '05 #1
1 1884
Hi,

On Mon, 19 Sep 2005 17:27:40 +0200, <cc****@mqsoftware.com> 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" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="myvar"
xmlns:myvar="myvariables">
<xsl:output 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::Properties)]"/>
</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/
Sep 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: JT | last post by:
I have an input form for which I've created a "matrix" for user input. Basically, the user chooses a radio button and then through javascript, a select box is displayed to define a value for that...
7
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc....
4
by: celerystick | last post by:
This is an xsl question, comp.infosystems.www.authoring.stylesheets were not able to help , here goes .... With one xml file containing repeated element <subject>: ...
12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
2
by: Eric Tuomikoski | last post by:
Im having trouble with server side ASP with Javascript. I have an ADO recordset that returns a list of Times example: 7:00AM. I then populate the option box with the results. (see below) The...
5
by: GTi | last post by:
Whats wring with this code? <select class=EditField size="1" name="PlantUnitID" title="Select line"> <option value="0" >Standalone Unit</option> <option value="1" selected >Connected Unit...
7
by: prash.marne | last post by:
Hello, I have a simple form <form method="POST"> <select name="activity"> <option value="0">None</option> <option value="M" onclick="popup_onclick()">Select Multiple</option> <option...
3
by: Italio Novuas | last post by:
Hi all, let me begin by saying that I *ALMOST* have this complete! What I'm trying to do is make it so my text area shows the innerHTML of any select item with the same value. For example, if I...
8
by: ismailc | last post by:
Hi, I would like to change the text color of (<xsl:value-of select="Description") onmouseover of image. the javascript works, it's just that i can seem to get the name correct <td>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.