Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 717839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:27:29+00:00 2026-05-14T05:27:29+00:00

Given <xsl:variable name=datePrecision as=element()*> <p>Year</p> <p>Month</p> <p>Day</p> <p>Time</p> <p>Timestamp</p> </xsl:variable> The expression $datePrecision[5] returns

  • 0

Given

<xsl:variable name="datePrecision" as="element()*">
  <p>Year</p>
  <p>Month</p>
  <p>Day</p>
  <p>Time</p>
  <p>Timestamp</p>
</xsl:variable>

The expression

$datePrecision[5] 

returns a nodeSet containing one text node with value “Timestamp”, as expected.

Later in a template, with a context element having an attribute

@precision="5"

I try the following expressions but all return an empty string:

$datePrecision[@precision]
$datePrecision[number(@precision)]
$datePrecision[xs:decimal(@precision)]

However, the following sequence does what I want

<xsl:variable name="prec" select="number(@precision)"/>
... $datePrecision[$prec] ...

Using Oxygen/XML’s debugger I’ve stepped to the point where the expression is about to be evaluated and display the following in the watch window:

Expression                          Value            Nodes/Values Set
--------------------------          ---------------  -----------------------
$datePrecision[5]                   Node Set(1)      #text Timestamp
@precision                          Node Set(1)      precision 5
$datePrecision[@precision]  
number(@precision)                  5
$datePrecision[number(@precision)]  
$prec                               5
$datePrecision[$prec]               Node Set(1)      #text Timestamp

Obviously I’ve missed something fundamental about how attribute nodes are atomized for use in a predicate, but can’t find anything in the docs (Michael Kay’s XSLT/XPATH 2.0, 4th ed) that would explain this difference.

Can someone explain why this is occurring, and point me to where, in either the XSLT 2.0 spec or Michael Kay’s book, where this is described?

(the XSLT processor is Saxon-PE 9.2.0.3)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:27:30+00:00Added an answer on May 14, 2026 at 5:27 am

    Obviously I’ve missed something
    fundamental

    Yes. The XPath expression:

    $datePrecision[@precision]
    

    means: all elements in $datePrecision that have an attribute named precision.

    But you want @precision to mean the attribute named precision of the currnet node that is matched by the template.

    XSLT provides the current() function exactly for this purpose. Use:

     $datePrecision[current()/@precision]
    

    UPDATE: As Martin Honnen hinted, the OP probably wants to get the 5th element out of $datePrecision — something not immediately visible from the description of the problem. In this case, it may be necessary to use:

     $datePrecision[position() = current()/@precision]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given An XSLT stylesheet with a global variable: <xsl:variable name=lang select=/response/str[@name='lang']/> Question Where from
<xsl:choose> <xsl:when test=long convoluted expression> <xsl:element name=Class>123</xsl:element> <a lot more xsl:elements> </xsl:when> <xsl:when test=next
I have two XSLT variables as given below: <xsl:variable name=staticBaseUrl select='https://www.hello.com/htapi/PrintApp.asmx/getGames?contentId=id_sudoku&uniqueId=123456&pageformat=a4' /> <xsl:variable name=dynamicUrl
Given the xml: <element>text</element> ... <element>text</element> And xsl: <xsl:for-each select=element> ... </xsl:for-each> What do
I'm having trouble with sum'ing up values in a variable. XSLT Source <xsl:variable name=amountIn
Given an XSL 'If' statement: <xsl:if test=a = 'some value' and b = 'another
Given the following XML: <?xml version=1.0 encoding=UTF-8 ?> <?xml-stylesheet type=text/xsl href=form.xsl?> <Document> <Translations> <Translation
In the below XSL every time the xsl:when gets satisfied I want to append
Given a normal nhibernate config file: <?xml version=1.0?> <?xml-stylesheet type=text/xsl href=http://localhost/xmlStylesheets/nhibernate.xsl?> <hibernate-configuration xmlns=urn:nhibernate-configuration-2.2> <session-factory>
Given the following XML: <results name=queryResults> <int name=intfield1:[* TO 10]>11</int> <int name=intfield2:[10 TO 20]>9</int>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.