Subject: Re: [xsl] Can't get output from xml -> text transformation From: "Todd Alexander" <heeznow@xxxxxxx> Date: Fri, 13 Aug 2004 11:38:24 -0700 |
Thanks, Todd Alexander heeznow@xxxxxxx
From: "M. David Peterson" <m.david@xxxxxxxxxx> Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] Can't get output from xml -> text transformation Date: Wed, 11 Aug 2004 12:25:06 -0600
Hi Todd,
Understanding what nodes are being processed and matched to a template will help in your understanding of whats happening. <xsl:apply-templates /> is the same thing as <xsl:apply-templates select="*"/> which will select all the children of the current context (root) and seek out a template to match them to (in your case there are no matching templates to the children of context - one node by the name of "allGamesDownloadable" - and as such the "value" of each child node is simply sent to the output "as is" until there are no more children left to process. The "blank" lines you are seeing are most likely the newline characters that exist as child "text" nodes of "allGamesDownloadable" in your source XML.
It seems that what you are expecting to happen is for every node (every child of a child of a child etc...) to be processed according to document order and when there is not matching template it will simply move to the next child or grandchild until it finds a match. While this is in no way an uncommon mistake - in fact its a VERY common mistake - it is fundamentally flawed from an XSLT template matching perspective and as such will not provide you the results you are looking for. If you try to think of it from the perspective that to gain access to the children of the current context node you must begin the recursive nature of apply-templates when the desired children are in context you will find yourself catching your errors quite easily... for example, the following will select the children of the root node, find the best matching template, process it accordingly, and then begin the recursive process on the children of the current context node ("allGamesDownloadable") by once again calling apply-templates at a time when the children are in context. Because we are using "*" for our match value the same template will match the children currently being processed which means any children of these children will be recursively processed and matched to the same template and this process will continue until every node in the source document has gone through "the ringer" so to speak...
so this....
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" />
<xsl:template match="/"> <xsl:text> GAMEID,GAMENAME </xsl:text> <xsl:apply-templates/> </xsl:template>
<xsl:template match="*"> <xsl:value-of select="@gameId"/>, <xsl:apply-templates/> </xsl:template>
Will output the value of @gameId for every node that is processed by this template that has an attribute gameId.
While this particular case will not give you the CSV output you are in desire of this should give you just enough information to help move you in the right direction...
Best of luck to you!
<M:D/>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Can't get output from xml, M. David Peterson | Thread | [xsl] Omit Data While Using Copy, Trevor Majic |
Re: [xsl] Need exactly 23 rows of o, Clay Leeds | Date | Re: [xsl] grouping + global variabl, Wendell Piez |
Month |