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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:22:18+00:00 2026-05-17T01:22:18+00:00

Again a simple thing. I have a stylesheet that parses XML and XSL files.

  • 0

Again a simple thing. I have a stylesheet that parses XML and XSL files. Basically, it tries to detect if the XML is a stylesheet with:

<xsl:if test="count(//xsl:template)!=0">

It does indeed detect stylesheets. It has problems with XML files, though, which generate an “Undefined namespace prefix – ‘xsl’” error. (In XmlSpy. Similar errors in the project I’m working on.)

I’m doing something wrong. Any suggestions on how to improve this stylesheet?


Some additional information: This is a stylesheet that’s meant to analyse other XML files, no matter what they contain. It should be able to transform itself even, and does so nicely. It has no problem transforming other (normal) stylesheets either. The problem arrives when I try to transform a regular XML file. Yet not all XML files…


As it turns out, the error is something else. The XML files that I tried to transform contain a processing instruction. This one: <?xml-stylesheet href="..\MyStylesheet.xsl" type="text/xsl"?>
The problem I have now is that when I process an XML file that contains this PI, the XSLT starts reporting the error about the undefined namespace prefix. So, how do I tell the XSLT processor to ignore this processing instruction?

  • 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-17T01:22:18+00:00Added an answer on May 17, 2026 at 1:22 am

    Double check how you have declared the xsl namespace and what namespace-prefix you have chosen.

    You need to ensure that the xsl namespace prefix is defined in your stylesheet if you want to use it in your XPATH expressions. You will get that error when you try to use a namespace prefix that has not been declared.

    If it isn’t declared anywhere further up in the stylesheet(typically on the document element like this: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">), or if you have chosen a different namespace prefix (e.g. declared it as “xslt” like this: xmlns:xslt="http://www.w3.org/1999/XSL/Transform"), then when you attempt to reference “xsl” it won’t know what you are referring to.

    You can declare the xsl namespace prefix on your if statement as a quick test:

    <xsl:if test="count(//xsl:template)!=0" 
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    

    Any suggestions on how to improve this
    stylesheet?

    You can simplify your test condition to select the xsl:template elements, rather than evaluating the count() of them. The results of test="//xsl:template" will evaluate as true() if something is selected, and false() if nothing is selected.

    In stylesheets xsl:template are top level constructs that are children of the document element. Rather than using // to recurse through every node in the XML document tree, you can use a more efficient XPATH expression:

    <xsl:if test="/*/xsl:template" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple update statement: UPDATE W SET state='thing' WHERE state NOT
Ok, so I have a simple c++ program that's supposed to run a couple
I have a bunch of HTML files, and what I want to do is
I have a simple database with about 3900 entries, and am using a generic
Warning: I have no clue about how to work with XML. I have a
I've got an archive file containing multiple audio files in .mp3 format. I can
I have a website, and in the Contact section I have a form which
I am playing around again with ASP.NET, and tried to set a cookie in
I'm working on a problem where I need to have a way to convert
Here I go again with some PLSql.. I want to know, if there's any

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.