Subject: Re: [xsl] Matching a bundle of elements From: Andrew Welch <andrew.j.welch@xxxxxxxxx> Date: Wed, 20 Jul 2011 10:49:31 +0100 |
On 20 July 2011 10:19, Emma Burrows <Emma.Burrows@xxxxxxxxxxx> wrote: > I am converting a large body of legacy XML documents to a DITA-based format using Oxygen 12. One of the problems with the document I'm currently working on is that about 15 different element names in the source will be turned into <topic> elements. I'm finding that I'm having to repeat those 15 elements in various templates in order to create the document maps, normalise cross references, etc. This makes the code difficult to read and is also prone to error if I accidentally miss off one of the elements in a given location. > > Is there any way in XSLT 2.0 that I can define the source elements as a group and then refer to that in templates, for-each loops and so on? Or are there any extension functions out there that might help? You could define a function like this: <xsl:function name="f:get-elements" as="element()*"> <xsl:param name="context"/> <xsl:sequence select="$context/(foo | a:bar | b:baz)"/> </xsl:function> and then call f:get-elements(.) wherever you want to select those elements, such as: <xsl:for-each select="f:get-elements(.)"> ..... </xsl:for-each> The . in the function call passes in the context, and the function returns the foo, a:bar, and b:baz child elements of that context in document order, so its the same as doing xsl:for-each select="foo | a:bar | b:baz" Alternatively, if the 15 element appear once in your xml (not recurring), just use a variable. Another alternative is to use schema-aware xslt and match on the common type, if the xsd is defined that way. You could possibly define your own common subtype and match on that.. not sure. -- Andrew Welch http://andrewjwelch.com
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Matching a bundle of elements, Emma Burrows | Thread | Re: [xsl] Matching a bundle of elem, Michael Kay |
[xsl] Matching a bundle of elements, Emma Burrows | Date | Re: [xsl] Query info on XSD., Michael Kay |
Month |