[xquery-talk] Unusual XPath syntax question

Michael Kay mike at saxonica.com
Mon Oct 31 11:17:02 PDT 2016

I agree with the other respondents: apart from giving an error if the context item is not a node, "./." is precisely equivalent to ".".

(Not sure why an XSLT question is appearing on the XQuery list...)

There's a certain fondness for verbosity in some parts of the XSLT user community. It's quite common to see "./price" where "price" would serve perfectly well, or "price/text()" for "price"; or xsl:element and xsl:attribute used where literal result elements would do the job, or (my favourite gripe)

<xsl:variable name="x">
  <xsl:value-of select="count(y)"/>

where <xsl:variable name="x" select="count(y)"/> would serve the purpose better.

And of course we've all seen things like <xsl:if test="contains(x, y) = true()">. 

I think some XSLT programmers must be paid by the yard; alternatively the language attracts those who love the sourd of their own keyboard. But "./." isn't an expansion I have seen before.

Michael Kay

> On 31 Oct 2016, at 16:52, Schwartz, Christine <christine.schwartz at ptsem.edu> wrote:
> Hi,
> I'm hoping someone on this list can clarify my conundrum.
> I'm working with a colleague on a writing project and one of his examples uses this XPath syntax "./." in the starts-with() function within an XSLT stylesheet. I don't know what "./." means. I would think that "." alone would be sufficient to refer to the context node.
> Here's the example: 
> <xsl:for-each select="//dim:field">
>    <xsl:if test="./@element='title'">
> 	<xsl:choose>
> 	   <xsl:when test="starts-with(./.,'The ')">
> 		 <datafield tag="245" ind1="1" ind2="4">
> 			<subfield code="a"><xsl:value-of select="."/>.</subfield>
> 		 </datafield>
> 	   </xsl:when>
> 	   <xsl:when test="starts-with(./.,'An ')">
> 		 <datafield tag="245" ind1="1" ind2="3">
> 			<subfield code="a"><xsl:value-of select="."/>.</subfield>
> 		 </datafield>
> 	   </xsl:when>
> 	   <xsl:when test="starts-with(./.,'A ')">
> 		 <datafield tag="245" ind1="1" ind2="2">
> 			<subfield code="a"><xsl:value-of select="."/>.</subfield>
> 		 </datafield>
> 	   </xsl:when>
> 	   <xsl:otherwise>
> 	        <datafield tag="245" ind1="1" ind2="0">
> 		      <subfield code="a"><xsl:value-of select="."/>.</subfield>
> 	        </datafield>
> Thanks, 
> Chris
> Christine Schwartz
> Metadata Librarian and XML Database Administrator
> Princeton Theological Seminary
> Library
> P.O. Box 821
> Princeton, NJ 08542
> christine.schwartz at ptsem.edu
> (609) 497-7938
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk

More information about the talk mailing list