Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 22nd, 2006, 08:16 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default Changing the attribute values in XSLT

Hallo guys,

I have a trouble with my XSLT. I am obtaining my XML Data regularly online from a weather service, which has the date values in german under the @Wochentag Attribute. I wanna change them into english.

Here is the code chunk

----------------

<xsl:for-each select="WETTERONLINE/prognosen/dreitage[@wmo = $wmo]">
   <xsl:for-each select="Tag[@Nummer = $day]">
     <tr>


              <td height="18" colspan="2" align="left" valign="top"><strong><xsl:value-of select="@Wochentag"/>
----------------

So what should I do? Should I use the apply templates? For example if I want to change the @Wochentag value from Montag to Monday what should I do?




__________________
Your attitude determines your altitude
 
Old May 22nd, 2006, 09:01 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You could do

<xsl:apply-templates select="@Wochentag"/>

and then

<xsl:template match="@Wochentag[.='Montag']">Monday</xsl:template>
<xsl:template match="@Wochentag[.='Dienstag']">Tuesday</xsl:template>
<xsl:template match="@Wochentag[.='Mittwoch']">Wednesday</xsl:template>

usw.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 22nd, 2006, 09:21 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks very much. I did it but I am now having an error message saying:

"Keyword xsl:stylesheet may not contain xsl:apply-templates"
What should I do?
my xsl:stylesheet element is

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/xhtml1/strict" >

What is wrong with it? Could you please help me?

 
Old May 22nd, 2006, 09:47 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The xsl:apply-templates is an instruction, it needs to go inside a template, for example as a replacement for your current xsl:value-of instruction.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 23rd, 2006, 02:02 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by mhkay
 The xsl:apply-templates is an instruction, it needs to go inside a template, for example as a replacement for your current xsl:value-of instruction.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Hallo Michael. Thanks for your reply. What I did is:


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/xhtml1/strict" >




<xsl:param name="day" /> // 3 day weather it is not the parameter of Wochentag
<xsl:param name="wmo"/>//city code
<xsl:param name="zeit"/> // time



<xsl:template match="/">
<xsl:apply-templates select="@Wochentag"/>

<div id="epoPage"><div id="epoHomeContent">
<div id="epoWeather" style="display:blocked">


-----


<xsl:for-each select="WETTERONLINE/prognosen/dreitage[@wmo = $wmo]">
   <xsl:for-each select="Tag[@Nummer = $day]">

     <tr>
             <xsl:template match="@Wochentag[.='Montag']">Monday</xsl:template>
              <td height="18" colspan="2" align="left" valign="top"><strong><xsl:value-of select="@Wochentag"/>



        <xsl:text> </xsl:text>
          <xsl:variable name="year" select="substring(@Datum,3,2)" />
          <xsl:variable name="month" select="substring(@Datum,6,2)" />
          <xsl:variable name="dayNumber" select="substring(@Datum,9,2)" />
          <xsl:value-of select="$dayNumber" />.<xsl:value-of select="$month" />.<xsl:value-of select="$year" /></strong></td>


</xsl:for-each>

</xsl:for-each>

   </table></div>
<div id="epoWeatherTab">
<div class="epoWeatherBorderLeft"> <a href="javascript:Day('1')" ><xsl:if test="$day = '1'"><xsl:attribute name="class" >aktive</xsl:attribute></xsl:if><xsl:value-of select="//Tag[1]/@Wochentag"/></a></div>
<div class="epoWeatherBorderLeft"> <a href="javascript:Day('2')"><xsl:if test="$day = '2'"><xsl:attribute name="class" >aktive</xsl:attribute></xsl:if><xsl:value-of select="//Tag[2]/@Wochentag"/></a></div>
<div class="epoWeatherBorderLeft"> <a href="javascript:Day('3')"><xsl:if test="$day = '3'"><xsl:attribute name="class" >aktive</xsl:attribute></xsl:if><xsl:value-of select="//Tag[3]/@Wochentag"/></a></div>

</div></div></div>
</xsl:template>

</xsl:stylesheet>

So now it doesn't give an error for apply-templates but it gives an error for the red marked line. I couldn't get the idea where to put this template value to change the name of the week.


 
Old May 23rd, 2006, 03:53 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default


I'm sorry, but you really need to start with a basic tutorial on XSLT. Unless you have a basic knowledge of the structure of the language, the only way to answer your questions is to write all the code for you. Personally, I wouldn't start using a new language without first buying a book: but if you prefer, there are plenty of online tutorials.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
changing attribute value in MS word cse.sandeep XSLT 4 June 7th, 2007 05:54 AM
Access to attribute values from class of attribute jacob C# 1 October 28th, 2005 01:11 PM
changing the value of attribute name stone XSLT 1 October 21st, 2005 06:35 AM
changing attribute value in xslt rameshnarayan XSLT 1 August 16th, 2005 08:07 AM
different values with the same attribute name srini XSLT 0 January 21st, 2004 05:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.