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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:31:07+00:00 2026-05-31T17:31:07+00:00

I’m trying to figure out how XSLT process namespace prefixes and have following example:

  • 0

I’m trying to figure out how XSLT process namespace prefixes and have following example:
XML:

<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" 
    xmlns:xhtml="http://www.w3.org/1999/xhtml" 
    xmlns:zno="http://feed.zinio.com/atom" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.w3.org/2005/Atom 
                      http://www.w3.org/1999/xhtml 
                      http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd
                      http://feed.zinio.com/atom" >
    <entry>
        <author>
            <name>By Sheila F. Buckmaster</name>
        </author>
        <category xml:lang="en" term="TRAVEL"/>
        <content>
            <h2 class="hl2">One of the world’s most entrancing cities becomes even more captivating when costumed revelers fill its tiny streets and grand piazzas during Carnevale. It is here that a star of the silent screen comes alive, antics and all</h2>
            <div class="byline">By Sheila F. Buckmaster</div>
        </content>
   </entry>
</feed>

XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xslt:stylesheet version="1.0" xmlns:xslt="http://www.w3.org/1999/XSL/Transform"
                           xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                           xmlns:user="urn:my-scripts"
                           xmlns:x="http://www.w3.org/1999/xhtml" 
                           xmlns:AP="http://www.w3.org/2005/Atom"
                           exclude-result-prefixes="xslt msxsl user">

    <xslt:output method="xml" indent="yes"/>
    <xslt:template match="/">
        <xslt:apply-templates select="/AP:feed//AP:entry"/>
    </xslt:template>

    <xslt:template match="AP:entry">
        <xslt:text>Hello from entry</xslt:text>
        <xslt:apply-templates select="AP:content"/>
    </xslt:template>

    <xslt:template match="AP:content">
        <xslt:text>Hello from content</xslt:text>
        <xslt:apply-templates select="x:div[@class='byline']"/>
    </xslt:template>

    <xslt:template match="x:div[@class='byline']">
        <xslt:copy-of select="."/>
    </xslt:template>
</xslt:stylesheet>

What I’m trying to do is to get access to my “div”. “Entry” and “Content” templates work fine since I specified namespace explicitly. But when I’m trying to get access to “div” using XHTML prefix (“x” in my case) – XSLT does not see it. It works only when I prefix “div” element with “AP” namespace:

    <xslt:template match="AP:content">
        <xslt:text>Hello from content</xslt:text>
        <xslt:apply-templates select="AP:div[@class='byline']"/>
    </xslt:template>

    <xslt:template match="AP:div[@class='byline']">
        <xslt:copy-of select="."/>
    </xslt:template>

But this doesn’t look right to me because DIV element should be in XHTML namespace. What am I doing wrong here?

  • 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-31T17:31:08+00:00Added an answer on May 31, 2026 at 5:31 pm

    The Atom feed has the Atom namespace declared on the root element without a namespace prefix. The <div/> and other XHTML elements are inheriting the Atom namespace because they do not have the XHTML namespace explicitly declared.

    If you want the XHTML elements to be bound to the XHTML namespace then you would need to change the <div> in the Atom feed to be:

    <div xmlns:xhtml="http://www.w3.org/1999/xhtml" class="byline">By Sheila F. Buckmaster</div>
    

    or:

    <xhtml:div class="byline">By Sheila F. Buckmaster</xhtml:div>
    

    If you keep the Atom feed the same and still want to generate XHTML elements, then you will need to adjust your stylesheet to match on AP:div and then construct XHTML elements in the output.

    For example, modifying your stylesheet I apply-templates on the matched AP:div in a mode named xhtml. There is a template matching on any element in that mode (so it would also work for the AP:h2) that constructs XHTML elements using the local-name() of the matched element.

    <?xml version="1.0" encoding="UTF-8"?>
    <xslt:stylesheet version="1.0" xmlns:xslt="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxsl="urn:schemas-microsoft-com:xslt"
        xmlns:user="urn:my-scripts"
        xmlns:x="http://www.w3.org/1999/xhtml" 
        xmlns:AP="http://www.w3.org/2005/Atom"
        exclude-result-prefixes="xslt msxsl user">
    
        <xslt:output method="xml" indent="yes"/>
        <xslt:template match="/">
            <xslt:apply-templates select="/AP:feed//AP:entry"/>
        </xslt:template>
    
        <xslt:template match="AP:entry">
            <xslt:text>Hello from entry</xslt:text>
            <xslt:apply-templates select="AP:content"/>
        </xslt:template>
    
        <xslt:template match="AP:content">
            <xslt:text>Hello from content</xslt:text>
            <xslt:apply-templates select="AP:div[@class='byline']"/>
        </xslt:template>
    
        <xslt:template match="AP:div[@class='byline']">
            <xslt:apply-templates select="." mode="xhtml"/>
        </xslt:template>
    
        <!--create an XHTML element with the same name as the context element -->
        <xslt:template match="*" mode="xhtml">
            <xslt:element name="{local-name()}" namespace="http://www.w3.org/1999/xhtml">
                <xslt:apply-templates select="@*|node()" mode="xhtml"/>
            </xslt:element>
        </xslt:template>
    
        <!--attributes, comments, and processing-instructions simply copied -->
        <xslt:template match="@*|text()|comment()|processing-instruction()">
            <xslt:copy-of select="."/>
        </xslt:template>
    
    </xslt:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.