Subject: Re: [xsl] If vs. apply-templates for optional attributes From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Fri, 7 Jun 2002 16:36:08 +0100 |
Hi Peter, >> <xsl:template match="xxx"> >> <xxx attr="default"> >> <xsl:copy-of select="@*"/> >> .. >> </xxx> >> >> which will mean that xxx has the attributes from the source, plus >> possibly attr="default" if teh source did not have that attribute. > > Yes, but that doesn't help if the source also has specified the > attribute. In that case I'd end up with it defined twice... No; an element can only have one copy of an attribute (XSLT never generates non-well-formed XML unless you start using disable-output-escaping), and the way XSLT works is that if you add an attribute to an element, but the attribute is already present, the new attribute gets added. Here, the attr attribute is added through the literal attribute on the xxx element, and then (if present in the source) is overridden by the attribute from the source. So what David suggested would work very well -- you get the default value if the attr attribute hasn't been specified, and the value of the attr attribute if it has. 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 -> |
---|---|---|
RE: [xsl] If vs. apply-templates fo, Hunsberger, Peter | Thread | Re: [xsl] If vs. apply-templates fo, David Carlisle |
Re: [xsl] Re: xsl to HTML, Michael Beddow | Date | RE: [xsl] James Clark on Schema, Wendell Piez |
Month |