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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:41:18+00:00 2026-06-16T20:41:18+00:00

I have the below XML file that i want to parse to create HTML.

  • 0

I have the below XML file that i want to parse to create HTML. My problem is that i am not able to parse it as I would like.

What i want to do is output my <items> as html. So i want a <paragraph> to be a <div>, <image>to be an <img> and its child nodes to be its properties ‘src’ and ‘alt’.

<itemlist>
    <item>
        <paragraph>pA</paragraph>
        <image>
            <url>http://www.com/image.jpg</url>
            <title>default image</title>
        </image>
        <paragraph>pB</paragraph>
        <paragraph>pC</paragraph>
        <link target='#'>linkA</link>
        <paragraph>pD</paragraph>
        <link target='#' >linkB</link>
        <image>
            <url>http://www.com/image2.jpg</url>
            <title>default image 2</title>
        </image>
        </item>
        <item>      
        <paragraph>pB</paragraph>
        <paragraph>pC</paragraph>
        <image>
            <url>http://www.com/image2.jpg</url>
            <title>default image 2</title>
        </image>
        <link target='#'>linkA</link>
        <paragraph>pD</paragraph>
        <link target='#'>linkB</link>
        </item>
    </itemlist>

If I do a foreach loop on <item> and write values by applying the templates, such as match=’paragraph’ followed by match=’image’, then all <paragraph> will be written before the <image>, which will not result in correct output.

Below is the output that i am expecting. Anyone has an idea how to do it?

<div id="item">
    <div>pA</div>
    <img src='http://www.com/image.jpg' title='default image' />
    <div>pB</div>
    <div>pC</div>
    <a href='#'>linkA</a>
    <div>pD</div>
    <img src='http://www.com/image2.jpg' title='default image 2' />
</div>
<div id="item">
    <div>pB</div>
    <div>pC</div>
    <img src='http://www.com/image2.jpg' title='default image 2' />
    <a href='#'>linkA</a>
    <div>pD</div>
    <a href='#'>linkB</a>
</div>

—–edit—-
Currently I have something like this

    <xsl:for-each select="itemlist/item">
<xsl:apply-templates select="paragraph"/>
<xsl:apply-templates select="link"/>


  <xsl:template match="paragraph">
<xsl:value-of select="." />
  </xsl:template>

  <xsl:template match="link">
<xsl:value-of select="." />
  </xsl:template>


</xsl:for-each>
  • 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-16T20:41:20+00:00Added an answer on June 16, 2026 at 8:41 pm

    Is this what you are looking for ? :

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="xml" encoding="UTF-8" />
    
        <xsl:template match="//paragraph">
            <div>
                <xsl:apply-templates select="@*|node()"/>
            </div>
        </xsl:template>
    
        <xsl:template match="//image">
            <img>
                <xsl:apply-templates select="@*|node()"/>
            </img>
        </xsl:template>
    
        <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>
    
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple but huge xml file like below. I want to parse
I have an XML file which I want to parse(below). I used an example
I want to parse text from a xml file.Consider that I have a some
I have the following code below, and I want to save that xml file
I have an XML file which has many section like the one below: <Operations>
I have a sample xml file which looks like the one below: <Root> <SubOne>
I have to parse a 1Gb XML file with a structure such as below
I have an XML file that I want to sort by an attribute. The
I have an xml file as below and I want to read data from
I have an XML file that I want to transform using an XSLT. 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.