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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:23:05+00:00 2026-05-22T14:23:05+00:00

I have an .xml which I need to display using XSL. Now, the entities

  • 0

I have an .xml which I need to display using XSL. Now, the entities in the XML are videos with tags. Not sure if it matters, but a video can have multiple tags.

Goal: What I need to do, is to (for a specific page) show all items that have the tag “cat1” for example. This is simple enough, I’ll just use an if:

<xsl:if test="tag[. =&#34;cat1&#34;]">

However, it should also NOT list the h1-tag in case there are no items tagged with “cat1” – that should only be displayed IF there are any videos with the tag “cat1”.

Problem: If there ARE videos with “cat1” present, no problem.
If there ARE NO videos with the tag “cat1” present, the h1-tag will be shown, but no videos. This is obviously not acceptable.

So the question becomes;

How do I filter the video-items first by checking their tags, and only after making sure there are still videos left, display the rest of the code?

Here is the code for the xml:

<videos>
    <video>
        <title>Video title</title>
        <subtitle></subtitle>
        <description_long>
            <![CDATA[Description]]>
        </description_long>
        <link language="English">http://URL here</link>
        <tag>cat1</tag>
    </video>
</demos>

Here is the code for the .xsl I’ve been trying:

<xsl:template match="/">
    <xsl:for-each select="videos/video">
        <xsl:sort data-type="text" order="ascending" />
        <xsl:if test="tag[. =&#34;cat1&#34;]">
            <h1>Category 1 videos</h1>
            <div class="video">
                <xsl:value-of select="title" />
            </div>
        </xsl:if>
        </xsl:choose>
    </xsl:for-each>
</xsl:template>
  • 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-22T14:23:06+00:00Added an answer on May 22, 2026 at 2:23 pm

    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="video[tag='cat1'][1]">
      <h1>Category 1 videos</h1>
      <xsl:apply-templates select="../video[tag='cat1']" mode="process"/>
     </xsl:template>
    
     <xsl:template match="video" mode="process">
      <p><xsl:value-of select="title"/></p>
     </xsl:template>
    
     <xsl:template match="text()"/>
    </xsl:stylesheet>
    

    when applied on the provided XML document (corrected to be well-formed and added a second video element):

    <videos>
        <video>
            <title>Video title</title>
            <subtitle></subtitle>
            <description_long><![CDATA[Description]]></description_long>
            <link language="English">http://URL here</link>
            <tag>cat1</tag>
        </video>
        <video>
            <title>Video title 2</title>
            <subtitle></subtitle>
            <description_long><![CDATA[Description]]></description_long>
            <link language="English">http://URL here</link>
            <tag>cat1</tag>
        </video>
    </videos>
    

    produces the wanted result:

    <h1>Category 1 videos</h1>
    <p>Video title</p>
    <p>Video title 2</p>
    

    When applied on this XML document (no cat1):

    <videos>
        <video>
            <title>Video title</title>
            <subtitle></subtitle>
            <description_long><![CDATA[Description]]></description_long>
            <link language="English">http://URL here</link>
            <tag>cat2</tag>
        </video>
        <video>
            <title>Video title 2</title>
            <subtitle></subtitle>
            <description_long><![CDATA[Description]]></description_long>
            <link language="English">http://URL here</link>
            <tag>cat2</tag>
        </video>
    </videos
    

    >

    again the wanted answer (nothing) is produced.

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

Sidebar

Related Questions

I have an xml resultset which has to be converted using XSL for display
I have an XML file which I need to parse using PHP and send
I have a xml which is max 3 levels deep. Now by using C#
HI I have an xml file with 500KB size which i need to send
I have a business class which I need to serialize to xml. It has
i have a log file which contains hundreds/thousands of seperate XML messages and need
I have been using a product which displays parsed XML files as HTML. It
I have one application in which list of videos that are coming through xml
I have made use of xsl:when to display my details. The details which I
I have an xml file which I need to visualize in a pdf file.

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.