Subject: Re: [xsl] Conditional text using attributes -- saxon:evaluate? From: Michael Smith <smith@xxxxxxxxxxx> Date: 28 Dec 2000 23:23:18 -0800 |
Steve, Your augmented identity transformation is just what I had in mind -- conditional inclusion based only on attribute names/values. To further parameterize it, would it be possible to also specify an attribute name as a parameter along with the value -- if not using "standard" XSLT, maybe instead with an application-specific extension function like Saxon's saxon:evaluate? For example, it would be very nice to be able to do something like: saxon test.xml beth.xsl attribute='os' value='PC' Is that possible? It would be great not to need to explicitly specify the attribute name within the stylesheet/transform itself. --Mike Smith (I put one more comment after the following quoted stuff.) Michael Smith <smith@xxxxxxxxxxx> writes: > | So instead of importing the DocBook templates, might it be possible > | instead to write a straight XML to XML "conditional inclusion" > | transform that will work with *any* well-formed XML document instance? > | > | What I mean specifically is a transform that: > | > | * conditionally includes elements based simply on attribute > | names/values, without regard at all for the actual element names > | > | * is a "standalone" transform that doesn't rely on importing other > | stylesheets that contain templates matching the element names > | > | Is that possible? How could it be expressed in XSLT? Steve Muench <Steve.Muench@xxxxxxxxxx> writes: > The following stylesheet augments the identity transformation with a > template that suppresses copying to the result any element which > *HAS* an "os" attribute whose value is *different* from the current > top-level os parameter value. > > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> > > <xsl:param name="os">Mac</xsl:param> > > <!-- Identity Transformation --> > <xsl:template match="node()|@*"> > <xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy> > </xsl:template> > > <!-- > | If element HAS an os attribute and its value is NOT > | what we're looking for, then squelch it > +--> > <xsl:template match="*[@os and @os!=$os]"/> > > </xsl:stylesheet> > > [...] This assumes that if an element has os="Mac" -- and the > current value of the $os param = "PC" -- that you want that element > AND ALL OF ITS CONTENT to be squelched along with it. I think squelching all of the element's child nodes is exactly what most document authors would want -- that is, the capability to recursively exclude whole sections/chunks of documents, along with excluding simple inline content. -- Michael Smith mailto:smith@xxxxxxxxxxx XML-Doc http://www.xml-doc.org/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Conditional text using at, Steve Muench | Thread | Re: [xsl] Conditional text using at, Steve Muench |
Re: [xsl] Carrying Namespaces throu, Kevin McCarthy | Date | RE: [xsl] utf-16 encoding, Julian F. Reschke |
Month |