Welcome to WebmasterWorld Guest from 54.234.153.186

Forum Moderators: httpwebwitch

Message Too Old, No Replies

XSL "attributes"

     

riderdan

9:04 pm on May 3, 2010 (gmt 0)

5+ Year Member



I have a problem that I can't quite solve, despite diligent digging via google, the W3C, and here on the forums.

I have an XML file that consists of todo items. Each item contains "attributes" that have a name, type, and value. I'm trying to get a sub-set of this information out so that I can display it on a Web page for tracking them. The closest I've gotten so far is a stylesheet that displays ALL the attributes--but I really only want the datedue and title.

Here's a snippet of the XML:

<object type="TODO" id="1">
<attribute name="datecompleted" type="date">292818951.40109300613403320312</attribute>
<attribute name="datedue" type="date">292748400.00000000000000000000</attribute>
<attribute name="title" type="string">Do something</attribute>
<attribute name="identifier" type="string">C6F2D32C-0A5A</attribute>
</object>

Here's my utterly failed XSLT:

<xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/TODO/attribute">
<xsl:value-of select="name()"/>
</xsl:template>
</xsl:stylesheet>

I can't for the life of me figure out how to get just the two types of attributes (name="title" and name="datedue") out

Help! :-)

httpwebwitch

5:35 pm on May 5, 2010 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Welcome to WebmasterWorld!

learn about XPath Predicates [w3schools.com].

e.g.:

//object/attribute[@name='datedue']

riderdan

7:39 pm on May 5, 2010 (gmt 0)

5+ Year Member



Thanks, that's put me on the right path :-)

httpwebwitch

12:25 am on May 7, 2010 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



<pun>you mean, the right XPath?</pun>

heh heh

httpwebwitch

12:27 am on May 7, 2010 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I apologize, that was uncalled for. I'm such a nerd...
 

Featured Threads

Hot Threads This Week

Hot Threads This Month