You are not logged in.

#1 2008-01-02 23:08:02

Reasons
Member
From: Washington
Registered: 2007-11-04
Posts: 572

Formating a xslt sheet?

In conky, I use a weather script which works amazing besides it does keep text looking nicely. Is there a way to align text to the right and/or change colors. I'm trying to get the condition (temp, wind, etc) one color and the output another with the output aligned to the right.

<!-- 

 This XSLT is used to translate an XML response from the weather.com
 XML API. 

 You can format this file to your liking. Two things you may feel 
 like doing:

    1) Modify the layout of the fields or static text already defined
    2) Add other fields from the XML response file that aren't referenced in this
       XSLT. You can grab a full list by just doing a: 
           wget "http://xoap.weather.com/weather/local/$LOCID?cc=*&unit=$UNITS" 
           (change $LOCID and $UNITS to suit your needs)
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" > 
    <xsl:output method="text" disable-output-escaping="yes"/>
    <xsl:template match="weather">
        <xsl:apply-templates select="loc"/>
        <xsl:apply-templates select="cc"/>
        <xsl:apply-templates select="dayf/day[@d='1']"/>
    </xsl:template>
 

    <xsl:template match="loc">
        <xsl:text>City:        </xsl:text><xsl:value-of select="dnam"/>
    </xsl:template>
    
    <xsl:template match="cc">
<!-- <xsl:text>City:       </xsl:text><xsl:value-of select="obst"/> --> 
<xsl:text>
</xsl:text>
<xsl:text>Temperature:              </xsl:text><xsl:value-of select="tmp"/><xsl:value-of select="/weather/head/ut"/>
<xsl:text>
Feels Like:                      </xsl:text><xsl:value-of select="flik"/><xsl:value-of select="/weather/head/ut"/>
<xsl:text>
Conditions:                         </xsl:text><xsl:value-of select="t"/>
<xsl:text>
Wind:                              </xsl:text>
<xsl:choose>
    <xsl:when test="wind/s = 'calm'"><xsl:text>0</xsl:text></xsl:when>
    <xsl:otherwise><xsl:value-of select="wind/s"/></xsl:otherwise>
</xsl:choose>
<xsl:value-of select="/weather/head/us"/><!-- 
<xsl:choose>
    <xsl:when test="wind/s = 'calm'"><xsl:text>(0mph)</xsl:text></xsl:when>
    <xsl:otherwise><xsl:text> (</xsl:text><xsl:value-of select="round(wind/s * 0.6214)"/><xsl:text>mph)</xsl:text></xsl:otherwise>
</xsl:choose> -->
<xsl:text> (</xsl:text><xsl:value-of select="wind/t"/>
<xsl:text>)</xsl:text>
    </xsl:template>

    <xsl:template match="dayf/day[@d='1']">
<xsl:text>
Tomorrow:                           </xsl:text><xsl:value-of select="low"/><xsl:value-of select="/weather/head/ut"/>
<xsl:text> - </xsl:text><xsl:value-of select="hi"/><xsl:value-of select="/weather/head/ut"/>
<xsl:text>
</xsl:text><xsl:text> Forecast:                                 </xsl:text><xsl:value-of select="part[@p='d']/t"/>
<xsl:text></xsl:text><xsl:value-of select="/weather/swa/a/t"/>
  <!-- <xsl:text>
  </xsl:text> -->
    </xsl:template>
</xsl:stylesheet>

Offline

#2 2008-01-04 07:55:31

LE_Shatai
Member
Registered: 2007-01-04
Posts: 26

Re: Formating a xslt sheet?

Hi

As the Output of the xsl is just plain text, you can insert directly any format directions.
You could apply css-divs, or align it in a table with td, if the desired output would be html.

As the output is used for conky, you have to insert the conky formating.
Unfortunatly, conky does not provide any format strings than color.

Conky uses the spaces und whitespaces in the input for formating.
So if you want to align the text, you have to add spaces and so on manually.

Offline

#3 2008-01-06 23:52:56

Reasons
Member
From: Washington
Registered: 2007-11-04
Posts: 572

Re: Formating a xslt sheet?

Is there any other way than spaces because as the values change, it'd mess it up? I have little knowledge of this so forgive my bad terms. Could I specify somewhere in the beginning of the file to make all text stay within "x" pixel width box and then do something like


<xsl:text>Temperature: </xsl:text> align=right<xsl:value-of select="tmp"/><xsl:value-of select="/weather/head/ut"/><align/

Last edited by Reasons (2008-01-06 23:53:32)

Offline

#4 2008-01-07 08:50:36

ibendiben
Member
Registered: 2007-10-10
Posts: 519
Website

Re: Formating a xslt sheet?

You could use awk/C printf command to automatically align right/left/center and pad lines with spaces to a ceartan width.
If you can explain a little bit more detailed what you want, and provide an example of how you intend it to look afterwarts I could help you with that.

Offline

#5 2008-01-08 01:02:33

Reasons
Member
From: Washington
Registered: 2007-11-04
Posts: 572

Re: Formating a xslt sheet?

Here is a general picture of my desktop, the script being the weather at the top. Unlike everything else, the output per like is only changed by spaces. While I could do this, if the forecast changed from rain/snow to just snow, then the spacing is off. The whole conky is 145 pixels in width and I'm trying to have the script specify it's own table of 145 so I can align the outputs to the right so it follows the same format as the bottom right conky.

200801071658361280x800sll4.th.png

Offline

#6 2008-01-08 08:25:08

ibendiben
Member
Registered: 2007-10-10
Posts: 519
Website

Re: Formating a xslt sheet?

I don't know whether you can use this but this is what I mend:

echo "WEATHER
Location: Puyallup, WA (98374)
Temperature: 37F
Feels Like: 34F
Conditions: Partly Cloudy
Wind: 5mph (SSW)
Tomorrow: 36F-44F
Forecast: Rain/Snow" | sed 's/: /: >>/' | awk 'BEGIN {FS=">>"} {printf("%-15s %20s\n",$1,$2)}'

***RESULT:***
WEATHER
Location:        Puyallup, WA (98374)
Temperature:                           37F
Feels Like:                               34F
Conditions:                Partly Cloudy
Wind:                         5mph (SSW)
Tomorrow:                         36F-44F
Forecast:                      Rain/Snow

Would this be like you want? With %<value>s you specify the width (in characters) of a column. If the string has less characters than <value> it fills up the gap with spaces. "-" means left aligned, "|" centered, nothing (default) is right aligned.

Last edited by ibendiben (2008-01-08 10:10:46)

Offline

#7 2008-01-08 10:32:06

ibendiben
Member
Registered: 2007-10-10
Posts: 519
Website

Re: Formating a xslt sheet?

Reasons wrote:

<xsl:text>Temperature: </xsl:text> align=right<xsl:value-of select="tmp"/><xsl:value-of select="/weather/head/ut"/><align/

I'm not familiar with xsl, but I'm quite sure above should be possible...

Offline

#8 2008-01-08 11:13:19

ibendiben
Member
Registered: 2007-10-10
Posts: 519
Website

Re: Formating a xslt sheet?

googling, I came across this website:
http://matthewhelmke.net/index.php/2007 … nky-part-2

from where I concluded conky has alignment possibilities too:

${color #D6CACA}CPU usage        ${alignr} PID     CPU%   MEM%
${color #c9d6d6} ${top name 1} ${alignr}${top pid 1}   ${top cpu 1}   ${top mem 1}
${color #c9d6d6} ${top name 2}${alignr}${top pid 2}   ${top cpu 2}   ${top mem 2}
${color #c9d6d6} ${top name 3}${alignr}${top pid 3}   ${top cpu 3}   ${top mem 3}

${color #D6CACA}Mem usage
${color #c9d6d6} ${top_mem name 1}${alignr}${top_mem pid 1}   ${top_mem cpu 1}   ${top_mem mem 1}
${color #c9d6d6} ${top_mem name 2}${alignr}${top_mem pid 2}   ${top_mem cpu 2}   ${top_mem mem 2}
${color #c9d6d6} ${top_mem name 3}${alignr}${top_mem pid 3}   ${top_mem cpu 3}

${alignc} if would want text centered; ${alignl} for left cool

Last edited by ibendiben (2008-01-08 11:16:45)

Offline

#9 2008-01-08 14:18:06

Reasons
Member
From: Washington
Registered: 2007-11-04
Posts: 572

Re: Formating a xslt sheet?

While conky has that feature, it won't work in the script.While conky has that feature, it won't work in the script.
ibendiben, that would be perfect.

Exactly what do I do, in more detail. The ECHO, I assume would go to the location (~/.scripts/weather.xslt) but after that, I'm lost. Will it all still update normally and aligned?

Last edited by Reasons (2008-01-08 23:37:57)

Offline

#10 2008-01-16 18:15:37

ibendiben
Member
Registered: 2007-10-10
Posts: 519
Website

Re: Formating a xslt sheet?

Why don't you post your concyrc here...
The output of your weather script is a good idea too.

Last edited by ibendiben (2008-01-16 18:16:56)

Offline

Board footer

Powered by FluxBB