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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:41:52+00:00 2026-06-17T22:41:52+00:00

I am trying to access a node inside an .xml file which uses namespaces

  • 0

I am trying to access a node inside an .xml file which uses namespaces and sort it. It is not working and I think that it has to do with the namespaces and not being able to qualify them properly.

I have an index.xml which I use to combine the documents that I need and looks like this:

<?xml version="1.0" encoding="ISO-8859-1"?>

<?xml-stylesheet type="text/xsl" href="merge.xsl"?>

<pic:catalog xmlns:pic = "pictureCatalog">
    <pic:logo>Logo</pic:logo>
    <Author>User Name</Author>
    <pic:allPhotos>photos</pic:allPhotos>
</pic:catalog>

the photos.xml looks like this:

<?xml version="1.0"?>
<pic:photoCatalog xmlns:pic="pictureCatalog">

    <pic:photo>
           <pic:title>Alcazar</pic:title>
           <pic:location>Segovia - Spain</pic:location>
           <pic:date>Jan 2013</pic:date>
           <pic:camera>Sony</pic:camera>
           <pic:resolution>12px</pic:resolution>
           <pic:format>.jpg</pic:format>
           <pic:description>
            Medieval Castle over the hill overlooking the city.
           </pic:description>
    </pic:photo>

</pic:photoCatalog>

And my xsl stylesheet looks like this:

 <!-- All the photos-->
   <xsl:template match = "pic:catalog/pic:allPhotos">
     <html>
         <head>
            <link rel="stylesheet" type="text/css" href="Style.css" />
         </head>
         <body>

        <xsl:for-each select="pic:photoCatalog/pic:photo"><br/>
              <xsl:sort select="pic:location"/>
              <xsl:value-of select="pic:photoCatalog/pic:photo/pic:location"/>
           </xsl:for-each>

         </body>
   </html>
   </xsl:template>

Can anyone help?

Bluetxxth

  • 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-06-17T22:41:53+00:00Added an answer on June 17, 2026 at 10:41 pm

    You have two XML files here, but your XSLT is only applied to index.xml, with no reference to photos.xml anywhere. You would normally excpect to see a document reference in the XSLT if you want to access a second XML document.

    It looks like the second file name is held in the pic:allPhotos element of index.xml, and that you want to access that file and iterate over the photos. In this case, you need to change your xsl:for-each to access the document like so

     <xsl:for-each select="document(concat(., '.xml'))/pic:photoCatalog/pic:photo">
    

    The next issue is that you are outputting a br element at this point, before the xsl:sort statement. This is not valid as the xsl:sort should immediately follow the follow the xsl:for-each.

    <xsl:for-each select="document(concat(., '.xml'))/pic:photoCatalog/pic:photo">
       <xsl:sort select="pic:location"/>
       <br/>
    

    Also, your xsl:value-of is not quite right. As the point this is called, you are in the xsl:for-each loop, and so positioned on a pic:photo element already, so it can be just simplified to this

    <xsl:value-of select="pic:location"/>
    

    Try the following XSLT

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:pic="pictureCatalog" exclude-result-prefixes="pic">
    
       <xsl:template match="/pic:catalog">
          <xsl:apply-templates select="pic:allPhotos"/>
       </xsl:template>
    
       <xsl:template match="pic:catalog/pic:allPhotos">
          <html>
             <head>
                <link rel="stylesheet" type="text/css" href="Style.css"/>
             </head>
             <body>
                <xsl:for-each select="document(concat(., '.xml'))/pic:photoCatalog/pic:photo">
                   <xsl:sort select="pic:location"/>
                   <br/>
                   <xsl:value-of select="pic:location"/>
                </xsl:for-each>
             </body>
          </html>
       </xsl:template>
    </xsl:stylesheet>
    

    Which outputs the following

    <html>
    <head>
    <META http-equiv="Content-Type" content="text/html">
    <link rel="stylesheet" type="text/css" href="Style.css">
    </head>
    <body><br>Segovia - Spain</body>
    </html>
    

    Your namespaces are all present and correct, by the way! (Well, assuming you have declared it corrected on the xsl:stylesheet too)

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

Sidebar

Related Questions

I'm trying to access an XML file using DOM. One node is already commented
I am trying to access information on a website that uses frames. When I
I am trying to access a file for xml parsing with this: InputStream inputStream
I am trying to support CORS in my Node.js application that uses the Express.js
I'm trying to access node node for this JSON message: { nodes: [ {
Hi I'm trying to access a WCF service which returns a JSON Array using
I have some functions inside a file. I'm trying to obtain all functions in
Here is the xml I am trying to access: <resourceStrings> <globalStrings> <string> <key>RptTitle1</key> <value>Title1</value>
I'm trying to access a particular native Windows API call from within a node.js
Having a MethodDeclarationSyntax Node, I'm trying to access its DocumentationCommentSyntax Node. I can obtain

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.