help with xlst .. only extract parts

P

Petra Meier

Hi, I hope this is a proper place to post :)

This is my XML file:

<?xml version="1.0" encoding="utf-8"?>
<foo>
<address>a lot of tags and text</address>
<hubid>a lot of tags and text</hubid>
<thestamps>
<stamp name="A1">bla</stamp>
<stamp name="A2">foo</stamp>
<stamp name="A3">muh</stamp>
<sub type="1">
<stamp name="B1">aaa</stamp>
<stamp name="B2">bbb</stamp>
<stamp name="B3">ccc</stamp>
</sub>
</thestamps>
</foo>

I have to extract all elements with tag name STAMP in that form
(without the ---- doc... ----):
---- document begin ----
A1 ... bla
A2 ... foo
A3 ... muh
B1 ... aaa
B2 ... bbb
B3 ... ccc

---- document end ----

this would be my XsL file

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<xsl:eek:utput method="html"/>
<xsl:template match="address"></xsl:template>
<xsl:template match="hubid"></xsl:template>
<xsl:template match="stamp[@name]">
<xsl:value-of select="@name"/>
<xsl:text> ... </xsl:text>
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>

I dont think this is very elegant and might be errorprone .. can you
do this better?

thank you so much

Petra
 
J

Joe Kesselman

I dont think this is very elegant and might be errorprone .. can you
do this better?

Yes. What you've got now won't come close to working.

.... Oh, you want us to tell you *how* to do it better? Set up a root
template, and from there use <xsl:apply-templates> with a select that
specifically requests processing of your <stamp>s. Then you only need a
template for stamp, and you're done.

Understanding why what you posted doesn't work, and how to apply the
above hint, is left as an exercise for the student. A good XSLT tutorial
will answer those questions and more; herewith, my standard pointer to
http://www.ibm.com/xml for many tutorials and articles about XML processing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top