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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:24:45+00:00 2026-05-27T21:24:45+00:00

With a simple XML like this <value> <num> <accession>111</accession> <sequence>AAA</sequence> <score>4000</score> </num> </value> I

  • 0

With a simple XML like this

<value>
    <num>
        <accession>111</accession>
        <sequence>AAA</sequence>
        <score>4000</score>
    </num>
</value>

I want to know if it is possible to access to a particular node from a node previously stored in a variable. The XSLT code is very short and explains better what I want to say

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
    <xsl:template match="/value/num">
        <xsl:variable name="node">
            <xsl:copy-of select="current()"/>
        </xsl:variable>
        <root>
          <xsl:copy-of select="$node"/>
        </root>
    </xsl:template>
</xsl:stylesheet>

So I store the node in the variable “node”. Then I can print the contents of the node with $node.

(EDIT) XML output

<root>
    <num>
        <accession>111</accession>
        <sequence>AAA</sequence>
        <score>4000</score>
    </num>
</root>

What I want to do is to print the contents of a sub-node, like this

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
    <xsl:template match="/value/num">
        <xsl:variable name="node">
            <xsl:copy-of select="current()"/>
        </xsl:variable>
        <root>
          <xsl:copy-of select="$node/accession"/>
        </root>
    </xsl:template>
</xsl:stylesheet>

But it gives an error (Component returned failure code: 0x80600008 [nsIXSLTProcessor.transformToFragment]) (check here)

(EDIT) The XML that I would want is

<root>
    <accession>111</accession>
</root>

NOTE: The question is not how can I get this output. The question is how, using a variable as in the XSLT provided, can I get this output.

(EDIT:SOLVED)
Actually it is possible, but as pointed out in the comments, the value of a variable has to be assigned with the “select” attribute if a node-set is required. So this code was not working since the variable had a tree fragment instead of a node-set stored in it (read more information here)

Thanks!

  • 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-27T21:24:46+00:00Added an answer on May 27, 2026 at 9:24 pm

    Try this:

    <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
        <xsl:template match="/value">
            <root>
                <xsl:for-each select="num">
                    <xsl:variable name="node" select="current()" />
                    <xsl:copy-of select="$node/accession" />
               </xsl:for-each>
            </root>
        </xsl:template>
    </xsl:transform>
    

    Note that I used xsl:transform instead of xsl:stylesheet. Also, consider using version 2.0 instead of 1.0 if you have a compliant processor, it adds a lot of useful features.

    I still don’t see your need for a variable, though.

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

Sidebar

Related Questions

Take a simple XML file formatted like this: <Lists> <List> <Note/> ... <Note/> </List>
How to load flex components using XML. The scenario is simple as like this,
I have a simple XML structure like, that when parse with simplexml_load_string generates this:
I have an XML document with (basically) looks like this: ... <param> <key>age</key> <value>10</value>
I have a very simple XML datasource structured like this: <datasource> <row> <column>Some text
I have a simple xml document that looks like the following snippet. I need
I'd like to serialize some simple data model into xml, I've been using the
I'd like to parse a simple, small XML file using python however work on
I am trying to deserialize an object from XML in Ruby. Something simple like:
I have an XML file with data stored like this: <myxml> <item name=column18>88744544</item> <item

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.