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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:04:53+00:00 2026-05-22T00:04:53+00:00

I have a simply XSLT 1.0 stylesheet, that turns XML documents in XHTML. I

  • 0

I have a simply XSLT 1.0 stylesheet, that turns XML documents in XHTML. I really want to be able to “include” the content of an XML file in another when needed. AFAIK it is simply not possible in XSLT 1.0, so I decided to move my processing to a simple Java app that would pre-process the XML, executing the “includes” recursively, and passing it to the default JDK XSLT processor. I have a XML schema that my documents must conform to.

The most used element is called “text”, and can have an “id” and/or a “class” attribute, which gets used for XHTML styling with CSS. This element gets turned into “p”, “div”, or “span” depending on the context.

What I would like to add, is the ability to define “unknown” elements in my input files, and have them transformed in a “text” element for further processing. If the “unknown” element’s name start with a capital letter, then it becomes a “text”, with “id” set to original name. Otherwise a “text” with “class” set to original name. Everything else in the unknown element should be kept as-is, and then it should be processed by XSLT as if it was originally in the input file. In other words, I would like to transform all unknown elements to for a valid XML document, and then process it with my stylesheet.

Can this be done in XSLT, possibly in a pre-processing “stylesheet”, or should I do that as pre-processing in Java? Performance here is not important. I would prefer a XSLT solution, but not if it’s much more complicated then doing it in Java.

  • 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-22T00:04:54+00:00Added an answer on May 22, 2026 at 12:04 am

    Well, since no one answered, I just tried it. While is is easier to do it in Java, it has one major drawback: since the code need to know the valid elements so that it recognize the unknown ones, you end up having to hardcode that in your code and have to recompile it if the XSLT template changes.

    So, I tried in XSLT and it also works. Let’s say you have:

    <xsl:template match="text">
        *processing*
        <xsl:call-template name="id_and_class"/>
        *processing*
    </xsl:template>
    

    where the template named id_and_class copies your id and classes attribute in the generated element, and you want unknown elements to be mapped to “text” elements, then you can do this:

    <xsl:template match="text">
        <xsl:call-template name="text_processing"/>
    </xsl:template>
    
    <xsl:template name="text_processing">
        *processing*
        <xsl:call-template name="text_id_and_class"/>
        *processing*
    </xsl:template>
    ...
    <xsl:template name="text_id_and_class">
         <xsl:choose>
            <!-- If name() is not "text", then we have an unknown element. -->
            <xsl:when test="name()!='text'">
                <!-- Processing of ID and class omitted ... -->
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="id_and_class"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    ...
    <!-- MUST BE LAST : Process unknown elements like a "text" element. -->
    <xsl:template match="*">
       <xsl:call-template name="text_processing"/>
    </xsl:template>
    

    If yon process the content of one specific element with a named template, then you can check in that template if the name matches, and use that for your special processing. Then you just have to put a <xsl:template match=”*”> at the end of your stylesheet and call the named template from there.

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

Sidebar

Related Questions

Again a simple thing. I have a stylesheet that parses XML and XSL files.
I have a simple C# Console App that reads in an XML file specified
I have the following code that applies a XSLT style Test.Xml.xslTransform = function(xml, xsl)
I have an XSLT 1.0 (2.0 is not an option) stylesheet which produces XHTML.
I have some very simple xml and xslt documents, which render in IE8 in
I'm looking to do some really simply XSLT on my XML document, which has
I'm using an XSLT stylesheet (by Antennahouse) to convert XHTML to an XSL-FO file.
I have an xml document that I am transforming with xslt into an xsl-fo
I have some source XML containing different elements that get transformed by a stylesheet
In WPF 3.5 (with SP1), I have simply StackPanel that I would like to

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.