Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: I want to have an empty textarea >Thread Next - Re: I want to have an empty textarea Re: I want to have an empty textareaTo: NULL Date: 2/9/2007 12:15:00 AM On Feb 9, 8:00 am, Cecil Westerhof <d...@dummy.nl> wrote: > roy axenov wrote: > > On Feb 8, 11:23 pm, Cecil Westerhof <d...@dummy.nl> > > wrote: > >> This is a piece of code from a xslt-file: > > >> <xsl:template match="SMS"> > >> <xsl:for-each select='.'> > > > As a side note, this is one of the silliest things I've > > ever seen and a textbook case of magical thinking in > > coding. It's not that I've never invoked foo to do bar > > without understanding either foo or bar--I did, but > > after being painfully bitten on my backside by that a > > few times I just said no. > > 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. -- Pavel Lepin | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
