Re: All teidata.pointer attributes
Lou Burnard <[email protected]>
| Newsgroups | gmane.text.tei.general |
|---|---|
| Message-ID | <[email protected]> |
Thanks Conal. I don't have any climactic excuse, but I realised just after my posting last night that this approach is only going to show the attributes which are directly declared in an element spec. But in fact most pointer-valued attributes get that way by being inherited from an attribute class. So something rather more complex is needed: you need to look for elements which have a memberOf child that names an attribute class which supplies an pointer-valued attribute ... or which inherits from another class which does. Writing the xslt to do that is left as an exercise for the reader, since it's Sunday and I am cooking. On 05/02/17 09:11, Conal Tuohy wrote: > Whoops I made a mistake in that message (I blame the Brisbane summer heat!) > > The code I had inside the templates was wrong: > > <!-- wrong! --> > <xsl:copy> > <xsl:attribute name="haspointer">true</xsl:attribute> > <xsl:copy-of select="@* | node()"/> > </xsl:copy> > > It should of course have applied templates to the children of the matched > elements: > > <xsl:copy> > <xsl:attribute name="haspointer">true</xsl:attribute> > <xsl:copy-of select="@*"> > <xsl:apply-templates/> > </xsl:copy> > > [turning the fan on now] > > On 5 February 2017 at 19:07, Conal Tuohy <[email protected]> wrote: > >> 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 <0466%20324%20297> >> > >