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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:10:47+00:00 2026-06-08T04:10:47+00:00

I am having a xml document like below, <chapter xmlns:xi=http://www.w3.org/2001/XInclude xml:id=chapter1> <title>First chapter</title> <section

  • 0

I am having a xml document like below,

<chapter xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="chapter1">
<title>First chapter</title>
<section xml:id="section1">
                <imageobject>
                    <imagedata fileref="images/image1.jpg"/>
                </imageobject>
                <imageobject>
                    <imagedata fileref="images/image5.jpg"/>
                </imageobject>
</section>
    <chapter xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="chapter2"   xml:base="../foder1/section2.xml">        
   <section xml:id="section2">
                    <imageobject>
                        <imagedata fileref="images/image2.jpg"/>
                    </imageobject>
                    <imageobject>
                        <imagedata fileref="images/image3.jpg"/>
                    </imageobject>
    </section>
    </chapter>
    <chapter xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="chapter3" xml:base="../folder3/section3.xml">  
   <section xml:id="section3">
                    <imageobject>
                        <imagedata fileref="images/image4.jpg"/>
                    </imageobject>
    </section>
   </chapter>
 </chapter>

I am using following XSLT which I got from another answer to get list of image paths list from given xml document. But it does not output First Chapter section1’s image paths.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>

<xsl:template match="/*">
<Imagedata>
<xsl:apply-templates select="chapter"/>
</Imagedata>
</xsl:template>

<xsl:template match="*/chapter">
<chapter>
<basepath><xsl:value-of select="@xml:base"/></basepath>
<xsl:apply-templates/>
</chapter>
</xsl:template>

<xsl:template match="imagedata">
<relativepath><xsl:value-of select="@fileref"/></relativepath>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>

I want a list of image paths output like below structure. With it I can access all images in section1 by “mainrelativepath” and section2, section3 images by basepath and relativepath nodes. Please help me to get First chapter’s image paths also with a different node.

<Imagedata>
    <mainrelativepath>images/image1.jpg</mainrelativepath>
    <mainrelativepath>images/image5.jpg</mainrelativepath>
<chapter>
    <basepath>../foder1/section2.xml</basepath>
    <relativepath>images/image2.jpg</relativepath>
    <relativepath>images/image3.jpg</relativepath>
</chapter>
<chapter>
    <basepath>../foder3/section3.xml</basepath>
    <relativepath>images/image4.jpg</relativepath>
</chapter>

Thanks in advance..!!

  • 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-08T04:10:48+00:00Added an answer on June 8, 2026 at 4:10 am

    This transformation:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
        <xsl:template match="/chapter">
            <Imagedata>
              <xsl:apply-templates select="section/*/imagedata">
                <xsl:with-param name="pElemName" select="'mainrelativepath'"/>
              </xsl:apply-templates>
                <xsl:apply-templates select="chapter"/>
            </Imagedata>
        </xsl:template>
    
        <xsl:template match="*/chapter">
            <chapter>
                <basepath>
                    <xsl:value-of select="@xml:base"/>
                </basepath>
                <xsl:apply-templates/>
            </chapter>
        </xsl:template>
    
        <xsl:template match="imagedata">
        <xsl:param name="pElemName" select="'relativepath'"/>
            <xsl:element name="{$pElemName}">
                <xsl:value-of select="@fileref"/>
            </xsl:element>
        </xsl:template>
        <xsl:template match="text()"/>
    </xsl:stylesheet>
    

    when applied on the provided XML document:

    <chapter xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="chapter1">
        <title>First chapter</title>
        <section xml:id="section1">
            <imageobject>
                <imagedata fileref="images/image1.jpg"/>
            </imageobject>
            <imageobject>
                <imagedata fileref="images/image5.jpg"/>
            </imageobject>
        </section>
        <chapter xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="chapter2"   xml:base="../foder1/section2.xml">
            <section xml:id="section2">
                <imageobject>
                    <imagedata fileref="images/image2.jpg"/>
                </imageobject>
                <imageobject>
                    <imagedata fileref="images/image3.jpg"/>
                </imageobject>
            </section>
        </chapter>
        <chapter xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="chapter3" xml:base="../folder3/section3.xml">
            <section xml:id="section3">
                <imageobject>
                    <imagedata fileref="images/image4.jpg"/>
                </imageobject>
            </section>
        </chapter>
    </chapter>
    

    produces the wanted, correct result:

    <Imagedata>
       <mainrelativepath>images/image1.jpg</mainrelativepath>
       <mainrelativepath>images/image5.jpg</mainrelativepath>
       <chapter>
          <basepath>../foder1/section2.xml</basepath>
          <relativepath>images/image2.jpg</relativepath>
          <relativepath>images/image3.jpg</relativepath>
       </chapter>
       <chapter>
          <basepath>../folder3/section3.xml</basepath>
          <relativepath>images/image4.jpg</relativepath>
       </chapter>
    </Imagedata>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML document that looks like this: <kmsg xmlns=http://url1 xmlns:env=url1 xmlns:xsi=http://www.w3.org/2001/XMLSchemainstance xsi:schemaLocation=http://location
I have an XML document that looks like this: <Data xmlns=http://www.domain.com/schema/data xmlns:dmd=http://www.domain.com/schema/data-metadata > <Something>...</Something>
This is my XML Document(Small Snippt). <?xml version=1.0 encoding=UTF-8 standalone=yes?> <w:document xmlns:w=http://schemas.openxmlformats.org/wordprocessingml/2006/main> <w:body> <w:p>
My XML comes in like this: <Document type=ContentPage> <Fields> <Field name=FaqCategory type=dropdown title=Select Category:
Having a XML document like this: <?xml version="1.0" encoding="UTF-8"?> <records type="array"> <record> <name>svn</name> <record-type>A</record-type>
having the following XML sample document, I need to issue an XPath/XQuery expression to
I am having trouble creating an XML document that contains a default namespace and
I am trying to create an XSLT to transform an XML document and having
Having this (simplified) XML: <?xml version=1.0 encoding=UTF-8?> <kml> <Document> <Placemark> <name>Poly 1</name> <Polygon> <coordinates>
I am having the below code. import xml.dom.minidom def get_a_document(name): return xml.dom.minidom.parse(name) doc =

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.