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

  • Home
  • SEARCH
  • 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 1013695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:08:36+00:00 2026-05-16T10:08:36+00:00

Consider the following XSLT script: <?xml version=1.0 encoding=ISO-8859-1?> <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform> <xsl:output method=text encoding=iso-8859-1/>

  • 0

Consider the following XSLT script:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text" encoding="iso-8859-1"/>

<xsl:variable name="stringmap">
<map>
<entry><key>red</key><value>rot</value></entry>
<entry><key>green</key><value>gruen</value></entry>
<entry><key>blue</key><value>blau</value></entry>
</map>
</xsl:variable>

<xsl:template match="/">
<!-- IMPLEMENT ME -->
</xsl:template>

</xsl:stylesheet>

I’d like this script to print redgreenblue.

Is there any way to treat the XML markup which is stored in the stringmap variable as a document of its own which I can run XPath queries on? I’m basically looking for something like

<xsl:for-each select="document($stringmap)/map/entry">
    <xsl:value-of select="key"/>
</xsl:for-each>

(except that the document() function expects an URI).

Motivation: I have various long <xsl:choose> elements which map a given string to another string. I’d like to replace all those with a single template which takes a ‘map’ argument (which is a simple XML document). My hope is that I can then replace the <xsl:choose> with a simple statement like <xsl:value-of select="$stringmap/map/entry/value[../key='$givenkey']"/>

I’m using XSLT 1.0 using xsltproc.

  • 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-16T10:08:37+00:00Added an answer on May 16, 2026 at 10:08 am

    You’re almost right, using document('') will allow you to process node sets inside the current stylesheet:

    <xsl:for-each select="document('')/xsl:stylesheet/xsl:variable[@name='stringmap']/map/entry">
        <xsl:value-of select="key"/>
    </xsl:for-each>
    

    It’s not necessary to define the map node set as a variable in this case:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet xmlns:data="some.uri" version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
      <data:map>
        <entry><key>red</key><value>rot</value></entry>
        <entry><key>green</key><value>gruen</value></entry>
        <entry><key>blue</key><value>blau</value></entry>
      </data:map>
    
      <xsl:template match="/">
        <xsl:for-each select="document('')/xsl:stylesheet/data:map/entry">
          <xsl:value-of select="key"/>
        </xsl:for-each>
      </xsl:template>
    
    </xsl:stylesheet>
    

    If you do not use xsl:variable as a wrapper, you must remember that a top level elements must have a non null namespace URI.

    In XSLT 2.0 it would’ve been possible to just iterate over the content in a variable:

    <xsl:variable name="map">
      <entry><key>red</key><value>rot</value></entry>
      <entry><key>green</key><value>gruen</value></entry>
      <entry><key>blue</key><value>blau</value></entry>
    </xsl:variable>
    
    <xsl:template match="/">
      <xsl:for-each select="$map/entry">
        <xsl:value-of select="key"/>
      </xsl:for-each>
    </xsl:template>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following XML: <?xml version=1.0 encoding=ISO-8859-1?> <catalog> <cd> <title>Empire Burlesque</title> <artist> <name>Bob</name> <surname>Dylan</surname>
Consider following SWT code example: http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet151.java?view=co How can I separate the inline defined class?
Consider following snippet code for xml. <rootnode> <child id=child1 ><![CDATA[child 1]]></child> <child id=child2 ><![CDATA[child
Consider following script (it's total nonsense in pseudo-language): if (Request.hostMatch(asfasfasf.com) && someString.existsIn(new String[] {brr,
consider following url: http://sitename.com/School/Admin/PageViewer i have a subfolder in School named UserFiles that contains
Consider following two examples: Example 1: <xs:import namespace=http://example.com/ns schemaLocation=test.xsd/> Example2: <sample:Data Test=true xsi:schemaLocation=http://example.com/test.xsd> How
Consider following example : public class SomeBusinessLayerService : DataService<MyEntityContainer> { [WebInvoke] void DoSomething(string someParam)
Consider following class class test { public: test(int x){ cout<< test \n; } };
Consider following scenario: I have RESTful URL /articles that returns list of articles user
Consider following program: static void Main (string[] args) { int i; uint ui; 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.