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 1017365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:41:34+00:00 2026-05-16T10:41:34+00:00

I’m working with an XSL stylesheet, and I’m trying to use the method shown

  • 0

I’m working with an XSL stylesheet, and I’m trying to use the method shown here to store a sorted subtree as a variable. I’m using saxon 8.7 vis the xml-maven-plugin to transform my XML file. Here’s the code that I have:

<xsl:variable name="miniDays">
    <xsl:for-each select="//day[position() > $firstPosToShow]">
        <xsl:sort select="@date" order="descending" />
        <xsl:copy-of select=".|@*" />
    </xsl:for-each>
</xsl:variable>

When I run the stylesheet, I get the following error:

Error at xsl:copy-of on line 598 of file:/D:/home/Projects/src/main/xsl/site.xsl:
  XTDE0420: Cannot create an attribute node (date) whose parent is a document node

If I just set the subtree to the variable without sorting, it works, but it’s not sorted:

<xsl:variable name="miniDays" select="//day[position() > $firstPosToShow]" />

If I set the copy-of statement’s select to “.”, it gets past that point, but gives me an error later on when I actually try to use the variable data. Here’s how it’s being used:

<xsl:for-each select="exsl:node-set($miniDays)">
    <xsl:variable name="in" select="local:calculate-total-in-days(.)" />
    <!-- do some stuff with the var -->
</xsl:for-each>

And the error:

Error on line 676 of file:/D:/home/Projects/src/main/xsl/site.xsl:
  XPTY0004: Required item type of first argument of local:calculate-total-in-days() is element(); supplied value has item type document-node()

The function:

<xsl:function name="local:calculate-total-in-days">
    <xsl:param name="days" as="element()*" />
    <!-- Do some calculations -->
</xsl:function>

Am I using exsl:node-set incorrectly? And what should be in the copy-of’s select, “.” or “.|@*”?

  • 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-16T10:41:35+00:00Added an answer on May 16, 2026 at 10:41 am

    There are a number of problems with your code:

    1. <xsl:for-each select="//day[position() > $firstPosToShow]"> . This will select every day element in the document that is at position $firstPosToShow+1 or bigger in the set of day children of its parent! Most probably you want (//day)[position() >= $firstPosToShow]

    2. <xsl:copy-of select=".|@*" /> . This copies the current element, but also copies its attributes. An attribute can be copied only when the parent is an element. This is not the case as the operations inside an untyped variable create a temporary tree (a document) and a document node cannot have attributes. The correct instruction is: <xsl:copy-of select="." />

    3. List itemIn the following code:

    the expression exsl:node-set($miniDays) again is of type document-node() and the <xsl:for-each> selects just one (this) node. This explains the raised error, because local:calculate-total-in-days(.) expects an element-argument but is passed a document node.

    The correct code is:

    <xsl:for-each select="exsl:node-set($miniDays)/*"> 
        <xsl:variable name="in" select="local:calculate-total-in-days(.)" /> 
        <!-- do some stuff with the var --> 
    </xsl:for-each>
    

    Also, exslt:node:set() is not required in XSLT 2.0, because there is no RTF type in XSLT 2.0, and in fact is not supported in Saxon 9.x. Therefore, the correct code will be:

    <xsl:for-each select="$miniDays/*"> 
        <xsl:variable name="in" select="local:calculate-total-in-days(.)" /> 
        <!-- do some stuff with the var --> 
    </xsl:for-each>
    

    Alternatively, you may consider specifying the type of $miniDays explicitly as element()* and this will simplify the code — it would not be necessary to use $miniDays/* — just $miniDays

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.