Subject: RE: [xsl] Default template match From: "Corey Spitzer" <cspitzer@xxxxxxxxx> Date: Fri, 30 Nov 2001 10:41:23 -0600 |
you could have something like this: <xsl:template match="*"> <xsl:param name="doc-ref"/> <xsl:choose> <xsl:when test="$doc-ref/customer/age > 17"> <adult>blah</adult> </xsl:when> <xsl:otherwise> default </xsl:otherwise> </xsl:choose> </xsl:template> -----Original Message----- From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Costantino_Sertorio@xxxxxxxxxx Sent: Friday, November 30, 2001 10:18 AM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] Default template match Hello, I have an XSL which has the purpose of "flattening out" some XML content, getting personal data from another external file. The output format is XML. What I would like to do is treat some tags in a special way (for example, "sex" will only output its content if the person for which I'm generating the output is of the correct gender), and leave other tags unchanged in the output document. So I wrote several templates for all "active" tags (that correspond to a special action), and a final "otherwise" template that simply copies the "non-active" templates to the output. The first question is, is it possible to define the default template without that long line such as "match="node()[name() != 'adult' and name() != 'object' and name() != 'content' and name() != 'gender']""? Second question: my XSL is cycling through a list of persons in an XML doc, and parsing a content document. To keep the reference to the correct person, I am passing the reference to that person's data as a variable through all templates. Is this the only way to do it (certainly not! :-) ? Are there more elegant ways to do this? Thank you, Costantino ... <xsl:template match="adult"> <!-- Output only if age > 17 --> <xsl:param name="doc-ref"/> <!-- pass the reference through the templates recursively --> <xsl:if test="$doc-ref/customer/age > 17"> <xsl:apply-templates select="./*"> <xsl:with-param name="doc-ref" select="$doc-ref"/> <!-- pass the reference through the templates recursively --> </xsl:apply-templates> </xsl:if> </xsl:template> <xsl:template match="gender"> <!-- Output only if person of appropriate sex --> <xsl:param name="doc-ref"/> <!-- pass the reference through the templates recursively --> <xsl:apply-templates select="current()[@gender = $doc-ref/customer/gender]/*"> <xsl:with-param name="doc-ref" select="$doc-ref"/> <!-- pass the reference through the templates recursively --> </xsl:apply-templates> </xsl:template> <!-- HOW DO I AVOID TO USE THIS HORRIBLE ROW, EXCLUDING ALL OTHER TEMPLATES? --> <xsl:template match="node()[name() != 'paste' and name() != 'object' and name() != 'content' and name() != 'gender']"> <xsl:param name="doc-ref"/> <!-- pass the reference through the templates recursively --> <xsl:copy> <xsl:apply-templates select="node()"> <xsl:with-param name="doc-ref" select="$doc-ref"/> </xsl:apply-templates> </xsl:copy> </xsl:template> ... XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Default template match, David Carlisle | Thread | RE: [xsl] Default template match, Michael Kay |
Re: [xsl] Default template match, David Carlisle | Date | [xsl] sort and sum, Maneshi Tuli |
Month |