Subject: Re: [xsl] Wrong XML-element being displayed after Transformation From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Wed, 17 Jul 2002 17:15:31 +0100 |
Hi Jochen, > I wonder why a part of the XML-Tree is displayed in the transformed > document, although I have no expression in the XSL-stylesheet. This is happening because of the built-in templates in XSLT. XSLT has a couple of built in templates, which say: - when you apply templates to an element, process its child elements - when you apply templates to a text node, give its value Together, it means that if you apply templates to an element but don't have an explicit template for that element, then its content gets processed and eventually you end up with the text that the element contains. In your case, you're apply templates to the module element from your template: > <xsl:template match="/"> > <xsl:apply-templates /> > </xsl:template> There's no template matching the module element, so the required and foo elements that it contains both get templates applied to them. There are no templates for either of those, so their children get templates applied as well -- the recordset elements. Only the recordset element within the required element has a template that matches it: > <xsl:template match="module/required/recordset"> > <form action="foo.html" method="post"> > advertnr<input type="Text" readonly="readonly" name="advertnr" > value="{element[@name='advertnr']}" class="readonly" /> > </form> > </xsl:template> The recordset within the foo element doesn't have a template, so again its content gets templates applied and so on until you get to the text node 'TESTTEXT'. That text node's content gets output as text. To stop this from happening, you have two choices. The first is to have a template that overrides the default template for text nodes and outputs nothing: <xsl:template match="text()" /> The second (and better) alternative is to only apply templates to the elements that you want to process. If you only want to process the recordset element in the required element, then tell the processor to apply templates to that element; don't tell it to process other elements: <xsl:template match="/"> <xsl:apply-templates select="module/required/recordset" /> </xsl:template> Then you can have your template match all recordset elements, secure in the knowledge that the only one that will be processed is the one within the required element: <xsl:template match="recordset"> ... </xsl:template> Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Wrong XML-element being displ, Jochen Metzger | Thread | [xsl] Schema and fixed attribute va, Bruno Chatel |
RE: [xsl] XML to EXCEL, Macaulay,Malcolm (US | Date | Re: [xsl] Wrong XML-element being d, Jochen Metzger |
Month |