Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XML/XSL/XPATH how to get a element value

Reply
Thread Tools

XML/XSL/XPATH how to get a element value

 
 
Kniffel
Guest
Posts: n/a
 
      09-07-2007
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" xmlnssl="http://www.w3.org/1999/XSL/
Transform">
<xslutput 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

 
Reply With Quote
 
 
 
 
Pavel Lepin
Guest
Posts: n/a
 
      09-07-2007

Kniffel <(E-Mail Removed)> wrote in
<(E-Mail Removed). 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.
 
Reply With Quote
 
 
 
 
Kniffel
Guest
Posts: n/a
 
      09-07-2007
> Read W3C's XPath 1.0 spec. Section 2.2, Axes, is of
> particular interest in your predicament.
>


Oh I read this some Hours ago, but I canīt get the clue!
I tested with preceding and peceding-sibling, but I think I didnīt
have the right syntax.
Everytime I get a Error "The stylesheet does not contain a document
element. ...maybe empty, or not well-formed..."

Do you have a little example for me?

 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      09-07-2007
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:isplayTime/@Aktiviert



--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
Kniffel
Guest
Posts: n/a
 
      09-07-2007
Things I tried:

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

still have no clue about XPATH, thatīs why I will test more things...


 
Reply With Quote
 
Pavel Lepin
Guest
Posts: n/a
 
      09-07-2007

Kniffel <(E-Mail Removed)> wrote in
<(E-Mail Removed). com>:
>> Read W3C's XPath 1.0 spec. Section 2.2, Axes, is of
>> particular interest in your predicament.

>
> Oh I read this some Hours ago, but I canÂīt get the clue!
> I tested with preceding and peceding-sibling, but I think
> I didnÂīt have the right syntax.
> Everytime I get a Error "The stylesheet does not contain a
> document element. ...maybe empty, or not well-formed..."


Your stylesheet is riddled with well-formedness bugs. I
recommend you drop whatever you're doing right now and read
a basic XML tutorial. Then an XPath tutorial. Then some
sort of introductory XSLT reading. Then get an XML parser
and an XSLT processor somewhere (I normally recommend
xmllint and xsltproc--those are command-line tools that
come with libxml2/libxslt). Armed with your newfound
knowledge and tools try debugging your stylesheet. If
there's still something you don't understand, come back
with a more specific request.

--
This chickenus crossed the roadus while yodelingus.
 
Reply With Quote
 
Kniffel
Guest
Posts: n/a
 
      09-07-2007
On 7 Sep., 16:13, Kniffel <(E-Mail Removed)> wrote:
> Things I tried:
>
> /preceding-sibling:Aktiviert
> preceding-sibling/Aktiviert
> /preceding-sibling:isplayDrivingTime/@Aktiviert
> /preceding-sibling:isplayDrivingTime/attribute::Aktiviert
> DisplayDrivingTime/@Aktiviert
> preceding-sibling:isplayDrivingTime[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:isplayTime/@Aktiviert
.../DisplayTime/@Aktiviert=

Still getting the same error...

 
Reply With Quote
 
Kniffel
Guest
Posts: n/a
 
      09-07-2007
On 7 Sep., 16:18, Pavel Lepin <(E-Mail Removed)> wrote:
> Kniffel <(E-Mail Removed)> wrote in
> <(E-Mail Removed). com>:
>
> >> Read W3C's XPath 1.0 spec. Section 2.2, Axes, is of
> >> particular interest in your predicament.

>
> > Oh I read this some Hours ago, but I canīt get the clue!
> > I tested with preceding and peceding-sibling, but I think
> > I didnīt have the right syntax.
> > Everytime I get a Error "The stylesheet does not contain a
> > document element. ...maybe empty, or not well-formed..."

>
> Your stylesheet is riddled with well-formedness bugs. I
> recommend you drop whatever you're doing right now and read
> a basic XML tutorial. Then an XPath tutorial. Then some
> sort of introductory XSLT reading. Then get an XML parser
> and an XSLT processor somewhere (I normally recommend
> xmllint and xsltproc--those are command-line tools that
> come with libxml2/libxslt). Armed with your newfound
> knowledge and tools try debugging your stylesheet. If
> there's still something you don't understand, come back
> with a more specific request.
>
> --
> This chickenus crossed the roadus while yodelingus.


My example I showed in my first post, is really minimal to the things
I have running!
The real XSL-file have 320 lines of code. Working Code! And I have 3
other XSL-files also running perfect!
And that thing I try is getting me the error!
When I remove these xsl:choose/when statement everything works!
And I only need the XPATH statement at this little point, because at
this point I have to jump back!
Till now I haven't to do that XPATH thing, but now!

Please help me more!

 
Reply With Quote
 
Kniffel
Guest
Posts: n/a
 
      09-07-2007
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

 
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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Move value from one form element to another, hidden element viaJavaScript OccasionalFlyer Javascript 6 07-29-2009 03:33 AM
XSD restriction of nesting an element within another element with aspecific attribute value? PeteOlcott XML 1 02-05-2009 06:39 AM
how to Update/insert an xml element's text----> (<element>text</element>) HANM XML 2 01-29-2008 03:31 PM
XSD - element, element value and attribute ? Matthet XML 2 09-24-2003 04:10 PM



Advertisments