Subject: RE: [xsl] match on attribute anywhere From: "Andrew Welch" <awelch@xxxxxxxxxxxxxxx> Date: Thu, 14 Feb 2002 13:48:03 -0000 |
>I thought the point of the question was that there were several >'whatever-else'-s, each with *specific* processing except for the one >common bit: whatever was to be generated should be wrapped in a 'span' >to change the colour if @mark='1' was present. Andrew? Sure. Take this piece of xml: <a> <b>hello</b> <c>world</c> </a> You could write some templates to display this. Then, say, someone added @mark: <a> <b>hello</b> <c mark='1'>world</c> </a> and told you that any element with @mark should be highlighted. This is fine for this example, as you could just modify the template for <c>. However, if you have several templates and the knowledge that @mark could appear on any element, it wouldnt be so easy. It would be great to add just one extra template to match @mark anywhere, and highlight its contents. Trevor's solution works well here, although I must admit I have only tested it on a small amount of data. It will however be used in the next release when I can finally get away from wd-xsl ;) Thanks for the suggestions Andrew === If I am right, here is a tidier version of my first attempt: For each element type or patterm 'x' write: <!-- add a mode to the template you already have --> <xsl:template match="x" mode="process"> do whatever for element type 'x', including possibly xsl:apply-templates *without* a mode. </xsl:template> To do the marking add: <!-- pick up any elements with a mark attribute --> <xsl:template match="*[@mark='1']" priority="2"> <span style="color:#FF0000"> <!-- go back and do the standard thing, using a different mode so that you do not recursively trigger this template --> <xsl:apply-templates select="." mode="process" /> </span> </xsl:template> <!-- and the others --> <xsl:template match="*"> <xsl:apply-templates select="." mode="process" /> </xsl:template> Though this version is easier to maintain (you don't have to have that extra match+call for every template), its probably slower - it does a template select twice for every node, where the original only did a double select for marked nodes. But then it had roughly twice as many templates to look at, so it could go either way. Regards, Trevor Nash -- Traditional training & distance learning, Consultancy by email Melvaig Software Engineering Limited voice: +44 (0) 1445 771 271 email: tcn@xxxxxxxxxxxxx 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] match on attribute anywhe, Trevor Nash | Thread | Re: [xsl] match on attribute anywhe, Jeni Tennison |
[xsl] Elements with Mixed contents, Sandeep Deshpande | Date | [xsl] Some general questions..., Ragulf Pickaxe |
Month |