Re: All teidata.pointer attributes
Conal Tuohy <[email protected]>
| Newsgroups | gmane.text.tei.general |
|---|---|
| Message-ID | <CAErBQuQttuwearD=xSVHm+qoEBDOdMpDtrh9G-WwwroAz+Ammw@mail.gmail.com> |
Borrowing Lou's suggested XPath, let me suggest a couple of ways to deploy
it in XSLT:
If you are using XSLT 2.0 (or later), then you can record the list of
"pointer" elements' names in a global variable, and then define a template
which matches elements whose names appear in that list.
<xsl:variable name="pointer-element-names" select="
document('http://www.tei-c.org/release/xml/tei/odd/p5subset.xml')
//t:elementSpec[t:attList/t:attDef/t:datatype/t:dataRef/@key='teidata.pointer']
/@ident
"/>
<xsl:template match="*[local-name() = $pointer-element-names]">
<!-- process the pointer element -->
<xsl:copy>
<xsl:attribute name="haspointer">true</xsl:attribute>
<xsl:copy-of select="@* | node()"/>
</xsl:copy>
</xsl:template>
That's likely to be the most efficient approach, because the "//" step is
expensive (traversing the entire ODD document), and storing the result in a
variable means you only perform this traversal once.
You can't do this in XSLT 1, though, because references to variables are
not allowed in template match expressions. You could, however, do something
like this:
<xsl:template match="*">
<xsl:copy>
<xsl:if test="local-name() = $pointer-element-names">
<xsl:attribute name="haspointer">true</xsl:attribute>
</xsl:if>
<xsl:copy-of select="@* | node()"/>
</xsl:copy>
</xsl:template>
Also in XSLT 1 you should be able to do without a variable, by including
the "document()" function call in the match expression, but performance
might not be very good (because of the "//" step, and also because some
older XSLT processors might not cache the result of the "document()"
function call).
<xsl:template match="
*[
local-name()=document('
http://www.tei-c.org/release/xml/tei/odd/p5subset.xml')
//t:elementSpec[t:attList/t:attDef/t:datatype/t:dataRef/@key='teidata.pointer']
/@ident
]
">
<xsl:copy>
<xsl:attribute name="haspointer">true</xsl:attribute>
<xsl:copy-of select="@* | node()"/>
</xsl:copy>
</xsl:template>
On 5 February 2017 at 09:17, Lou Burnard <[email protected]>
wrote:
> This information is not available from the document instance: you need to
> look at the ODD from which the schema that validates the document instances
> was generated.
>
> If you're using a document that is valid against TEI all, this will list
> all the elements concerned:
>
> <xsl:template xmlns:t="http://www.tei-c.org/ns/1.0"
> <http://www.tei-c.org/ns/1.0> match="/">
> <xsl:for-each select="document('http://www.*tei*-c.org/release/*xml*/
> *tei*/odd/*p5subset*.*xml*l')//t:elementSpec[
> t:attList/t:attDef/t:datatype/t:dataRef/@key='teidata.pointer']">
> <xsl:message><xsl:value-of select='@ident'/></xsl:message>
> </xsl:for-each>
>
>
> On 04/02/17 22:52, John P. McCaskey wrote:
>
> Running an XSL transform against a TEI document, I want to match all TEI
> elements that contain at least one teidata.pointer attribute.
>
> I can’t match just on attribute name. In some elements @value is a
> pointer, in others it’s text. Sometimes @class is a pointer, sometimes not.
>
> Is there a master list of attributes that can be pointers and the elements
> in which they are?
>
> (Even better if the list is in a form that makes it easy to use in an XSL
> match. Double extra better if you can show me the very XSLT that will copy
> the element and add an attribute “haspointer=’true’”!)
>
> Thanks!
> John
>
>
>
--
Conal Tuohy
http://conaltuohy.com/
@conal_tuohy
+61-466-324297