Discussion:
[xquery-talk] Unusual XPath syntax question
Schwartz, Christine
2016-10-31 16:52:38 UTC
Permalink
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
***@ptsem.edu
(609) 497-7938



_______________________________________________
***@x-query.com
http://x-query.com/mailman/listinfo/talk
Joe Wicentowski
2016-10-31 17:12:21 UTC
Permalink
Hi Christine,
Post by Schwartz, Christine
I don't know what "./." means. I would think that "." alone would be sufficient to refer to the context node.
Agreed - "./." gets you precisely ".". If "." is compact syntax for
"self::node()", then the expanded syntax for "./." would be
"self::node()/self::node()". Testing in oXygen shows that ". =
././././././././."!

Joe
_______________________________________________
***@x-query.com
http://x-query.com/mailman/listinfo/talk
Ghislain Fourny
2016-10-31 17:12:56 UTC
Permalink
Hi Christine,

In principle, in XPath, "./." is the same as "." and returns the context item. There is a minor difference, in that "./." will return an error if the context item is not a node, but in the case of the query at hand, it should always be an element node. Replacing "./." with "." produced the same results on my side.

I'd definitely wait for Mike's answer before concluding on this though, because he'll probably see something I haven't. :-)

Kind regards,
Ghislain
Post by Schwartz, Christine
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.
<xsl:for-each select="//dim:field">
<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
(609) 497-7938
_______________________________________________
http://x-query.com/mailman/listinfo/talk
_______________________________________________
***@x-query.com
http://x-query.com/mailman/listinfo/talk
G. Ken Holman
2016-10-31 17:20:43 UTC
Permalink
Yes, "." is the same as "./." and the shorter version (to me) would
be more suitable for legibility. The shorter syntax already is being
used in the select attribute, so I'm unclear what the author might be
trying to gain with the longer syntax.

. . . . . . Ken
Post by Schwartz, Christine
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.
<xsl:for-each select="//dim:field">
<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
(609) 497-7938
_______________________________________________
http://x-query.com/mailman/listinfo/talk
--
Check our site for free XML, XSLT, XSL-FO and UBL developer resources |
Streaming hands-on XSLT/XPath 2 training @US$45: http://goo.gl/Dd9qBK |
Crane Softwrights Ltd. _ _ _ _ _ _ http://www.CraneSoftwrights.com/q/ |
G Ken Holman _ _ _ _ _ _ _ _ _ _ mailto:***@CraneSoftwrights.com |
Google+ blog _ _ _ _ _ http://plus.google.com/+GKenHolman-Crane/posts |
Legal business disclaimers: _ _ http://www.CraneSoftwrights.com/legal |

_______________________________________________
***@x-query.com
http://x-query.com/mailman/listinfo/talk
Ihe Onwuka
2016-10-31 17:42:09 UTC
Permalink
On Mon, Oct 31, 2016 at 1:20 PM, G. Ken Holman <
Yes, "." is the same as "./." and the shorter version (to me) would be
more suitable for legibility. The shorter syntax already is being used in
the select attribute, so I'm unclear what the author might be trying to
gain with the longer syntax.
. . . . . . Ken
emphasis.
G. Ken Holman
2016-10-31 17:48:45 UTC
Permalink
Post by Ihe Onwuka
On Mon, Oct 31, 2016 at 1:20 PM, G. Ken Holman
Yes, "." is the same as "./." and the shorter version (to me) would
be more suitable for legibility. The shorter syntax already is being
used in the select attribute, so I'm unclear what the author might
be trying to gain with the longer syntax.
. . . . . . Ken
emphasis.
.... emphasizing what?

. . . . . . . Ken


--
Check our site for free XML, XSLT, XSL-FO and UBL developer resources |
Streaming hands-on XSLT/XPath 2 training @US$45: http://goo.gl/Dd9qBK |
Crane Softwrights Ltd. _ _ _ _ _ _ http://www.CraneSoftwrights.com/q/ |
G Ken Holman _ _ _ _ _ _ _ _ _ _ mailto:***@CraneSoftwrights.com |
Google+ blog _ _ _ _ _ http://plus.google.com/+GKenHolman-Crane/posts |
Legal business disclaimers: _ _ http://www.CraneSoftwrights.com/legal |

_______________________________________________
***@x-query.com
http://x-query.com/mailman/listinfo/talk
Michael Kay
2016-10-31 18:17:02 UTC
Permalink
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
Post by Schwartz, Christine
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.
<xsl:for-each select="//dim:field">
<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
(609) 497-7938
_______________________________________________
http://x-query.com/mailman/listinfo/talk
_______________________________________________
***@x-query.com
http://x-query.com/mailman/listinfo/talk
W.S. Hager
2016-10-31 22:12:02 UTC
Permalink
I just love to do .[1][1][1][1][1][1][1]
Post by Michael Kay
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 <
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.
<xsl:for-each select="//dim:field">
<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
(609) 497-7938
_______________________________________________
http://x-query.com/mailman/listinfo/talk
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Schwartz, Christine
2016-11-01 17:52:18 UTC
Permalink
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:***@gmail.com]
Sent: Monday, October 31, 2016 6:12 PM
To: Michael Kay <***@saxonica.com>
Cc: Schwartz, Christine <***@ptsem.edu>; ***@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" <***@saxonica.com<mailto:***@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
Post by Schwartz, Christine
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.
<xsl:for-each select="//dim:field">
<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
(609) 497-7938
_______________________________________________
http://x-query.com/mailman/listinfo/talk
_______________________________________________
***@x-query.com<mailto:***@x-query.com>
http://x-query.com/mailman/listinfo/talk
Ghislain Fourny
2016-11-02 09:21:11 UTC
Permalink
Hi Christine,

For your defence: this was technically an XPath question, and as such that is also relevant to XQuery :-)

Kind regards,
Ghislain
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
Sent: Monday, October 31, 2016 6:12 PM
Subject: Re: [xquery-talk] Unusual XPath syntax question
I just love to do .[1][1][1][1][1][1][1]
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
Post by Schwartz, Christine
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.
<xsl:for-each select="//dim:field">
<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
(609) 497-7938
_______________________________________________
http://x-query.com/mailman/listinfo/talk
_______________________________________________
http://x-query.com/mailman/listinfo/talk
_______________________________________________
http://x-query.com/mailman/listinfo/talk
_______________________________________________
***@x-query.com
htt

Loading...