[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Default template match
> 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']""? yes, just set it to match="*", the default priorities will ensure that it's only fired when none of the others match. > 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! :-) ? You haven't shown us the structure, but one would usually be able to reference the correct person by a path, e.g. ancestor::person. Mike Kay > > ... > <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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|