I am quite new to xml and xslt. (It is my first try.) So
how should I'll do this?
Well, you just don't need that for-each. It doesn't really
do anything. As to why you don't need it: the first step is
understanding what for-each really is in XSLT. It's not a
'loop' - there are no loops in XSLT, - it's an inline
template together with its application to a nodeset. That
is:
<xsl:template match="foo">
<xsl:for-each select="bar">
<template/>
</xsl:for-each>
</xl:template>
....is almost-equivalent to:
<xsl:template match="foo">
<xsl:apply-templates select="bar"
mode="absolutely-globally-unique-mode"/>
</xsl:template>
<xsl:template match="@*|node()"
mode="absolutely-globally-unique-mode">
<template/>
</xsl:template>
Not try translating your code into this template-based
form:
<xsl:template match="SMS">
<xsl:apply-templates select="."
mode="absolutely-globally-unique-mode"/>
</xsl:template>
<xsl:template match="@*|node()"
mode="absolutely-globally-unique-mode">
<!-- whatever goes into the for-each -->
</xsl:template>
Now the flaw should be obvious. The first template
doesn't do anything, except invoking another template with
the same context node. Note that the template invoked is
guaranteed to always match, and not to be invoked by any
other template (otherwise this construct might make sense
under some circumstances).
Any pointers what documentation to use to learn working
with xml and xslt? I have 'XML in a Nutshell', but that
is mere for reference instead of learning I think.
References are good (although I've no idea if the one
you've mentioned *is* good). The group regulars will
probably have some good books to recommend, but in my
opinion the best way to learn is learning by doing and
understanding. With one caveat: don't try that in
production environments. Reading comp.text.xml and trying
to solve other people's problems is an excellent way to
learn.
XSL FAQ (google it) is an excellent if somewhat poorly
organized reading.
Just one hint: if you come from imperative programming
background, you'll need a paradigm shift. Until you learn
by heart that XSLT is a functional, template-based
language, you won't be any good at using it efficiently.