• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Can I do this with XSLT?

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do I extract a list of 'states' using XSLT?
I want each state listed only once. Can XSLT do this?
Any suggestions appriciated.
My XML looks like this (but with many more stores)...
<?xml version="1.0"?>
<stores>
<store storename="Rocky's Auto">
<state>CO</state>
</store>
<store storename="John Elway Used Cars">
<state>CO</state>
</store>
<store storename="Wild Pete's Used Cars">
<state>FL</state>
</store>
</stores>

Output should be something like this...
<states>
<state>CO</state>
<state>FL</state>
</states>
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi !
You may do something like this...
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="stores">
<?xml version="1.0"?>
<states>
<xsl:apply-templates match="store"/>
</states>
</xsl:template>
<xsl:template match="store">
<state><xsl:value-of select="state"/></state>
</xsl:template>
</xsl:stylesheet>
I hope this is working & this will help you
Jean-Baptiste.
 
Billy Hause
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, but that solution doesn't list each state only once. I need to eliminate duplicates.
Thanks anyway.
-Bill
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Billy Hause
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That worked! Thanks
 
We noticed he had no friends. So we gave him this tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic