473,387 Members | 1,534 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,387 software developers and data experts.

XML/XSL/XPATH how to get a element value

Hi everyone

I do a xsl-transformation. And I try to get a Attribute, but I cannot
get it. My XML/XSL experience is not very good at the moment.

I have something like this:
TEST.xml
--------------
<?xml version="1.0" encoding="utf-8"?>
<Main>
<DisplayTime Aktiviert="True" />
<PrintTime Aktiviert="True" />
</Main>

TEST.xsl
-------------
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<xsl:output method="html" version="1.0" encoding="UTF-8"
indent="yes" />

<xsl:template match="/Main">
<table class="std" width="700px">
<form name="form" action="/Address" method="get"">
<tr><td colspan="2" class="std">
<xsl:apply-templates select="DisplayTime"/>
<xsl:apply-templates select="PrintTime"/>
</td>
</tr></form></table>
</xsl:template>

<xsl:template name="DisplayTime" match="DisplayTime">
<xsl:variable name="wert" select="name()" />
<xsl:for-each select="@*">
<xsl:variable name="DDTattr" select="name()" />
<xsl:variable name="DDTattrwert" select="." />
<xsl:choose>
<xsl:when test="$DDTattrwert='True'">
<input type="checkbox" name="DisplayTime_{$DDTattr}"
checked="checked">
Display Time
</input>
</xsl:when>
</xsl:choose>
</xsl:template>

<xsl:template name="PrintTime" match="PrintTime">
<xsl:variable name="wert" select="name()" />
<xsl:for-each select="@*">
<xsl:variable name="PTattr" select="name()" />
<xsl:variable name="PTattrwert" select="." />
/****** Here I need a choose/when on the Element 'Aktiviert' of
DisplayTime: ******/
<xsl:choose>
<xsl:when test="//DisplayTime/Aktiviert='True'">
/****** But I don't know how I can get it! *****/
<xsl:choose>
<xsl:when test="$DDTattrwert='True'">
<input type="checkbox"
name="DisplayTime_{$DDTattr}" checked="checked">
Display Time
</input>
</xsl:when>
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

How does the statement have to look like to get the Value of the
DisplayTime element when I am in PrintTime?

Greetings
Kniffel

Sep 7 '07 #1
5 5411

Kniffel <tw*********@gmx.dewrote in
<11**********************@w3g2000hsg.googlegroups. com>:
I do a xsl-transformation. And I try to get a Attribute,
but I cannot get it. My XML/XSL experience is not very
good at the moment.

I have something like this:
TEST.xml
--------------
<?xml version="1.0" encoding="utf-8"?>
<Main>
<DisplayTime Aktiviert="True" />
<PrintTime Aktiviert="True" />
</Main>

How does the statement have to look like to get the Value
of the DisplayTime element when I am in PrintTime?
Read W3C's XPath 1.0 spec. Section 2.2, Axes, is of
particular interest in your predicament.

--
This chickenus crossed the roadus while yodelingus.
Sep 7 '07 #2
Kniffel wrote:
<Main>
<DisplayTime Aktiviert="True" />
<PrintTime Aktiviert="True" />
</Main>
So the root element is the Main element with two child elements
DisplayTime and PrintTime having an attribute Aktiviert.
<xsl:template name="PrintTime" match="PrintTime">
<xsl:variable name="wert" select="name()" />
<xsl:for-each select="@*">
<xsl:variable name="PTattr" select="name()" />
<xsl:variable name="PTattrwert" select="." />
/****** Here I need a choose/when on the Element 'Aktiviert' of
DisplayTime: ******/
Aktiviert is not an element, it is an attribute of DisplayTime which is
a sibling of PrintTime. So you can go to the common parent and then
access the element and its attribute e.g.
../DisplayTime/@Aktiviert
or you can access the sibling e.g
preceding-sibling::DisplayTime/@Aktiviert

--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 7 '07 #3
Things I tried:

/preceding-sibling:Aktiviert
preceding-sibling/Aktiviert
/preceding-sibling::DisplayDrivingTime/@Aktiviert
/preceding-sibling::DisplayDrivingTime/attribute::Aktiviert
DisplayDrivingTime/@Aktiviert
preceding-sibling::DisplayDrivingTime[attribute::Aktiviert='False']

still have no clue about XPATH, thatīs why I will test more things...
Sep 7 '07 #4
On 7 Sep., 16:13, Kniffel <twongora...@gmx.dewrote:
Things I tried:

/preceding-sibling:Aktiviert
preceding-sibling/Aktiviert
/preceding-sibling::DisplayDrivingTime/@Aktiviert
/preceding-sibling::DisplayDrivingTime/attribute::Aktiviert
DisplayDrivingTime/@Aktiviert
preceding-sibling::DisplayDrivingTime[attribute::Aktiviert='False']

still have no clue about XPATH, thatīs why I will test more things...
And now I tried your ways:
preceding-sibling::DisplayTime/@Aktiviert
.../DisplayTime/@Aktiviert=

Still getting the same error...

Sep 7 '07 #5
So ......:

<xsl:variable name="PDTwert" select="/DLT/DisplayDrivingTime/
attribute::*" />
<xsl:choose>
<xsl:when test="$PDTwert='True'">
True
</xsl:when>
<xsl:when test="$PDTwert='False'">
False
</xsl:when>
</xsl:choose>

< >
o o
oooO.|.Oooo

Sep 7 '07 #6

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

Similar topics

1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
5
by: Tom Alsberg | last post by:
Hi there... I'm recently trying to get a bit acquainted with XML Schemas and XSL. Now, I have a few questions about XSL stylesheets and templates: * Is there a way to "enter" a child element...
4
by: Son KwonNam | last post by:
In XSLT, is this possible to get value from xml using XPath which is in XSLT variable? I mean XPath strings can be dynamic while XSL Transforming. If possible, How?? Because I'm not a...
4
by: MarcoT77 | last post by:
Hi Teacher. I'm trying to get with Xpath the Product nodes in the following XML: <?xml version="1.0" encoding="utf-8"?> <PLMXML xmlns="http://www.plmxml.org/Schemas/PLMXMLSchema"...
7
by: steve bull | last post by:
I have the following code snippet to read the colorRange attributes for the colorRangeSwatch in the xml file listed below. string expr = "/swatches/colorRangeSwatch/colorRange";...
3
by: Goran Djuranovic | last post by:
Hi All, Does anyone know how to retreive deepest XPath value from XML document by using VB.NET? For example, if I had an XML file like this: <Root> <Customer> <Name>MyName</Name> </Customer>...
2
by: Bilal | last post by:
Hello, I'm stuck on this problem for quite some time and hope somebody would be able to guide me. Basically, I need to populate a large number of "template" XML files which have all...
3
by: Jason Mobarak | last post by:
Hello -- I'm attempting to get a handle on how to do xpath queries with System.Xml -- so far the biggest hurdle has been how to deal with a default namespace. If I use the test xml: <?xml...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.