[xquery-talk] Unusual XPath syntax question

Schwartz, Christine christine.schwartz at ptsem.edu
Tue Nov 1 10:52:18 PDT 2016


Thank you to everyone who answered my question yesterday. I’m glad to know that “./.” is the same as “.” except that the longer version will throw an error if the context item is not a node. Since we are teaching beginners, I’m going to suggest to my colleague that we use the shorter version “.” in the example.

Also, sorry I wrote to the XQuery list for an XSLT question. I’m just not subscribed to an XSLT list, but really should be. After years of using XQuery as my “hammer” I’m starting to use XSLT more when appropriate.

Best,

Chris


Christine Schwartz
Metadata Librarian and XML Database Administrator
Princeton Theological Seminary Library




From: W.S. Hager [mailto:wshager at gmail.com]
Sent: Monday, October 31, 2016 6:12 PM
To: Michael Kay <mike at saxonica.com>
Cc: Schwartz, Christine <christine.schwartz at ptsem.edu>; talk at x-query.com
Subject: Re: [xquery-talk] Unusual XPath syntax question


I just love to do .[1][1][1][1][1][1][1]

Op 31 okt. 2016 19:19 schreef "Michael Kay" <mike at saxonica.com<mailto:mike at saxonica.com>>:
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)"/>
</xsl:variable>

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
Saxonica

> On 31 Oct 2016, at 16:52, Schwartz, Christine <christine.schwartz at ptsem.edu<mailto: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'<mailto:./@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<mailto:christine.schwartz at ptsem.edu>
> (609) 497-7938
>
>
>
> _______________________________________________
> talk at x-query.com<mailto:talk at x-query.com>
> http://x-query.com/mailman/listinfo/talk



_______________________________________________
talk at x-query.com<mailto:talk at x-query.com>
http://x-query.com/mailman/listinfo/talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://x-query.com/pipermail/talk/attachments/20161101/afde59bc/attachment.html>


More information about the talk mailing list