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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:43:31+00:00 2026-06-08T15:43:31+00:00

I am transforming some XML, renaming each element named alt-title to Running_Head , provided

  • 0

I am transforming some XML, renaming each element named alt-title to Running_Head, provided that the attribute alt-title-type is equal to “running-head”.


So, the below code is using the line <xsl:when test="starts-with(@alt-title-type, 'running-head')"> which is working fine. However, when I change this to either of these:

  • <xsl:when test="ends-with(@alt-title-type, 'running-head')">
  • <xsl:when test="matches(@alt-title-type, 'running-head')">

…this error is thrown:

Error:XSLTProcessor::transformToXml() [xsltprocessor.transformtoxml]:
xmlXPathCompiledEval: 2 objects left on the stack.

So, it seems that the function starts-with is working, where ends-with and matches are not.


Here is my XSL, using starts-with, that seems to be working properly:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="UTF-8" indent="yes" method="xml" />

    <!-- Running_Head -->
    <xsl:template match="@*|node()">
        <xsl:choose>

            <xsl:when test="starts-with(@alt-title-type, 'running-head')">
                <xsl:element name="Running_Head">
                    <xsl:apply-templates select="@*|node()"/>
                </xsl:element>
            </xsl:when>

            <xsl:otherwise>
                <xsl:copy>
                    <xsl:apply-templates select="@*|node()"/>
                </xsl:copy>
            </xsl:otherwise>

        </xsl:choose>
    </xsl:template> <!-- end of Running_Head -->

</xsl:stylesheet>

…and here is the XML being transformed:

<root-node>
    <alt-title alt-title-type="running-head">
        This is working
    </alt-title>
    <alt-title alt-title-type="asdfng-head">
        asdfasdf
    </alt-title>
    <alt-title>
        asdfasdf
    </alt-title>
    <alt-title alt-title-type="running-head">
        This is also working
    </alt-title>
</root-node>

I am testing this at http://xslt.online-toolz.com/tools/xslt-transformation.php, and http://www.xsltcake.com/.

  • 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-08T15:43:33+00:00Added an answer on June 8, 2026 at 3:43 pm

    As other people have pointed out, most XPath 2.0 functions (such as matches() and ends-with()) are not supported by an XSLT 1.0 processor.

    Moreover, these functions aren’t needed at all in a transformation that implements the current requirements:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="node()|@*">
      <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match="alt-title[@alt-title-type='running-head']">
      <Running_Head>
        <xsl:apply-templates select="@*|node()"/>
      </Running_Head>
     </xsl:template>
    </xsl:stylesheet>
    

    when this transformation is applied on the provided XML document:

    <root-node>
        <alt-title alt-title-type="running-head">
          This is working
      </alt-title>
        <alt-title alt-title-type="asdfng-head">
         asdfasdf
      </alt-title>
        <alt-title>
         asdfasdf
      </alt-title>
        <alt-title alt-title-type="running-head">
         This is also working
      </alt-title>
    </root-node>
    

    the wanted, correct reault is produced:

    <root-node>
       <Running_Head alt-title-type="running-head">
          This is working
      </Running_Head>
       <alt-title alt-title-type="asdfng-head">
         asdfasdf
      </alt-title>
       <alt-title>
         asdfasdf
      </alt-title>
       <Running_Head alt-title-type="running-head">
         This is also working
      </Running_Head>
    </root-node>
    

    Explanation:

    Proper use of templates, match patterns and overriding of the identity rule.

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

Sidebar

Related Questions

I am transforming some XML data to fit into document that is in a
I am transforming an XML document. There is an attribute @prettydate that is a
i want to transform some xml into HTML that has the following format: <TR><TD>
I'm transforming some XML, which I have no control over, to XHTML. The XML
Let's say I have some XSL transforming XML. Is it possible for the same
I'm transforming some XML from DrawingML to XAML. Unfortunately, the XAML one is not
I have a C# application that generates an html document from transforming an xml
When transforming some xml (dita) documents there is a problem with special characters, ampersand
I'm looking for some help with XSLT Tranforms. I'm currently transforming links that match
While transforming some data to SQL Azure, I have noted an unexpected behavior. I

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.