RE: match on attribute anywhere
>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
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