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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:20:54+00:00 2026-05-20T20:20:54+00:00

I just wrote an XSLT that did not work at first. I had to

  • 0

I just wrote an XSLT that did not work at first.

I had to rename all children of <Recordset> to <C>:

<?xml version="1.0" encoding="utf-8"?>
<Record>
<Recordset>
    <company>102</company>
    <store>1801</store>
    ....
</Recordset>
<Recordset>
....
</Recordset>
</Record>

I used the following XSLT:

<xsl:template match="Record/Recordset/child::*">    
    <xsl:element name="C">
        <xsl:apply-templates select="@*|node()"/>
    </xsl:element>
</xsl:template>

It works and renames all children of <Recordset> to <C>.
But first my match in the template looked like this:

<xsl:template match="Record/Recordset/child::node()">

My idea was that every child of <Recordset> is a node, thus node() would be appropriate.
It worked too but it inserted an extra <C/> for each child.

What’s the difference between child::node() and child::*?

  • 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-20T20:20:55+00:00Added an answer on May 20, 2026 at 8:20 pm

    child::node() matches any node that’s not an attribute node, namespace node, or document node. That means that it does match processing instructions, comments, and text nodes.

    child::* matches only elements.

    See section 5.5.3 of the spec:

    The pattern node() matches all nodes
    selected by the expression
    root(.)//(child-or-top::node()), that
    is, all element, text, comment, and
    processing instruction nodes, whether
    or not they have a parent. It does not
    match attribute or namespace nodes
    because the expression does not select
    nodes using the attribute or namespace
    axes. It does not match document nodes
    because for backwards compatibility
    reasons the child-or-top axis does not
    match a document node.

    Update: Michael’s answer inspired the following stylesheet. Use it to test the types of nodes as they’re processed:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:template match="/|node()">
            <xsl:call-template name="type" />
            <xsl:text>  [  </xsl:text>
            <xsl:value-of select="." />
            <xsl:text>&#10;</xsl:text>
            <xsl:apply-templates select="node()" />
            <xsl:text>  ]  </xsl:text>
        </xsl:template>
        <xsl:template name="type">
            <xsl:choose>
                <xsl:when test="count(.|/)=1">
                    <xsl:text>Root</xsl:text>
                </xsl:when>
                <xsl:when test="self::*">
                    <xsl:text>Element </xsl:text>
                    <xsl:value-of select="name()" />
                </xsl:when>
                <xsl:when test="self::text()">
                    <xsl:text>Text</xsl:text>
                </xsl:when>
                <xsl:when test="self::comment()">
                    <xsl:text>Comment</xsl:text>
                </xsl:when>
                <xsl:when test="self::processing-instruction()">
                    <xsl:text>PI</xsl:text>
                </xsl:when>
                <xsl:when test="count(.|../@*)=count(../@*)">
                    <xsl:text>Attribute</xsl:text>
                </xsl:when>
            </xsl:choose>
        </xsl:template>
    </xsl:stylesheet>
    

    Modify what’s matched/selected to test other patterns. For example, the following input:

    <A attr="test" other="val">
      <B/>
      <C>some value</C>
      <!-- a comment -->
      <D/>
    </A>
    

    Produces the following output:

    Root  [  
    
      some value
    
    
    
    Element A  [  
    
      some value
    
    
    
    Text  [  
    
      ]  Element B  [  
      ]  Text  [  
    
      ]  Element C  [  some value
    Text  [  some value
      ]    ]  Text  [  
    
      ]  Comment  [   a comment 
      ]  Text  [  
    
      ]  Element D  [  
      ]  Text  [  
    
      ]    ]    ]  
    

    Special thanks to this page for getting me started on the node-type tests. (It’s especially fitting that one of Michael’s answers from over six years ago appears there, too.)

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

Sidebar

Related Questions

I just wrote my first OpenMP program that parallelizes a simple for loop. I
I have an XML file that I want to transform using an XSLT. It
I am very new to XSLT, and the first thing that i need to
I just wrote a little application(4 page php), everything work fine, however, I have
I'd like to transform a string that contains an xml using a XSLT, it's
I'm trying to write an XSLT that will transform an XML document that I
Just wrote my first python program! I get zip files as attachment in mail
I just wrote my first Clojure function based on my very limited knowledge of
I just wrote a Qt program, and build it under Release type, it work
I just wrote some code that works very well. But I feel that it

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.