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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:04:11+00:00 2026-06-04T06:04:11+00:00

I have XML like this: <article> <title>Article 1 title</title> <text>Lorem ipsum…</text> <image>http://example.com/img_01.jpg</image> </article> <article>

  • 0

I have XML like this:

<article>
   <title>Article 1 title</title>
   <text>Lorem ipsum...</text>
   <image>http://example.com/img_01.jpg</image>
</article>
<article>
   <title>Article 2 title</title>
   <text>Dolor sit amet...</text>
   <image>http://example.com/img_02.jpg</image>
</article>

I need to show just relative path to the image and I want the absolute path to be written in another file. Let’s call it img_to_download.html.

Here’s my idea how to do it. I have one global variable called image_src_download where I append one absolute path string during every iteration of for-each (using the function f:download and giving it a parameter image_src). Then when for-each is finished, I put content of variable image_src_download to a separate file img_to_download.html.

My XSLT looks like this:

    <xsl:output method="html" encoding="UTF-8"/>

        <xsl:variable name="image_src"/> <!-- this is for a single entry-->
        <xsl:variable name="image_src_download"/> <!-- this should carry all sources to images -->

<!-- This function should append new string to the existing one in variable image_src_download -->
        <xsl:function name="f:download">
            <xsl:param name="newLink"/>
            <xsl:variable name="image_src_download">
                <xsl:value-of select="concat($image_src_download, $newLink, '\n')"/>
            </xsl:variable>
        </xsl:function>

        <xsl:template match="/">
            <html>
                <head>
                    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
                    <title>All articles</title>
                </head>
                <body>
                    <xsl:for-each select="article">
                        <h1><xsl:value-of select="title"/></h1>
                        <p><xsl:value-of select="text"/></p>

                        <xsl:variable name="image_src">
                            <xsl:value-of select="image"/>
                        </xsl:variable>
                        <xsl:variable name="image_src_rel">
                            <xsl:value-of select="substring($image_src, 20)"/> <!-- Strips beggining of the absolute URL and leaves just relative path to the file -->
                        </xsl:variable>

                            <xsl:value-of select="f:download($image_src)"/> <!-- This should append absolute path string of the current article image to variable image_src_download -->
                            <p><img src="{$image_src_rel}" /></p>
                    </xsl:for-each>

                </body>
            </html>

            <!-- Generates new file where there are absolute paths to images on each line-->
            <xsl:result-document href="img_to_download.html" method="html">
                <html>
                    <head>
                        <title>IMG to download</title>
                    </head>
                    <body>
                        <xsl:value-of select="$image_src_download"/>
                    </body>
                </html>
            </xsl:result-document>
        </xsl:template>

My desired output are two files.
File articles.html that looks like this:

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
      <title>All articles</title>
    </head>
    <body>
      <h1>Article 1 title</h1>
      <p>Lorem ipsum...</p>
      <p><img src="img_01.jpg"/></p>

      <h1>Article 2 title</h1>
      <p>Dolor sit amet...</p>
      <p><img src="img_02.jpg"/></p>
    </body>
</html>

File img_to_download.html that looks like this:

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
      <title>IMG to download</title>
    </head>
    <body>
      <p>
        http://example.com/img_01.jpg<br/>
        http://example.com/img_02.jpg<br/>    
      </p>
    </body>
</html>

Please, do you have an idea how to make this work?

All best, Johnny

  • 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-04T06:04:13+00:00Added an answer on June 4, 2026 at 6:04 am

    In XSLT, you can’t change variables once they are initialized. Instead, process the XML nodes twice with different modes in order to generate different output for the article elements. Maybe something like the following is sufficient for your task:

    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="html"/>
    
      <xsl:template match="/">
        <html>
          <head>...</head>
          <body>
            <xsl:apply-templates/>
          </body>
        </html>
        <xsl:result-document href="img_to_download.html" method="html">
          <html>
            <head>...</head>
            <body>
              <p>
                <xsl:apply-templates mode="extern"/>
              </p>
            </body>
          </html>
        </xsl:result-document>    
      </xsl:template>
    
      <xsl:template match="article">
        <h1><xsl:value-of select="title"/></h1>
        <p><xsl:value-of select="text"/></p>
        <p><img src="{tokenize(image, '/')[last()]}"/></p>
      </xsl:template>
    
      <xsl:template match="article" mode="extern">
        <img src="{image}"/>
        <br/>
      </xsl:template>
    
      <xsl:template match="text()" mode="#all"/>
    </xsl:stylesheet>
    
    • 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 like this: <xml> <item> <title>Article 1</title> <text><![CDATA[Lorem ipsum dolor
I have a XML (simplified) like this: <article> <title>My Article</title> <image src=someurl.jpg /> <image
I have XML that looks like this <xml> <news> <newsitem> <publishdate>2011-10-11</publishdate> <title>Article 1</title> <breakingnewsflag>false</breakingnewsflag>
Let's suppose I have xml like this one: <Server Active=No> <Url>http://some.url</Url> </Server> C# class
I have some xml like this: <Data> <Rows> <Row> <Field Name=title>Mr</Field> <Field Name=surname>Doe</Field> <Row>
I have an XML like this: <EXP> <TITLES> <SUBTITLE CL=AXT4 FL=1 NB=Text 1/> </TITLES>
hi i have an xml like this <?xml version=1.0?> <DataSetExchangeWMS xmlns=http://tempuri.org/DataSetExchangeWMS.xsd> <dtObjektInfo> <LanguageCode>1031</LanguageCode> <LiegenschaftID>7463</LiegenschaftID>
If I have some xml like this: <mynode> <mysubnode> <mysubsubnode>hello world</mysubsubnode> some more text
I have a .out file which has xml content like this. <header stub> <article
I have a previously generated XML like this: <newsletter> <header> </magazine> </image> <strap/> </header>

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.