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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:34:15+00:00 2026-05-23T11:34:15+00:00

How does one do a dynamic value-of? This is the case: 1) We get

  • 0

How does one do a dynamic value-of?

This is the case:

1) We get an XML-export from system A.
2) We select and format some of the data which is needed by system B.
3) One of the passed fields needs to be combined from multiple elements of the source xml.

The combined elements can be customized by the customer.

So, what I have now is this:
XSLT for transformation of the xml from system A
A simple configuration xml where the customer can specify which fields he wants to combine in a sequential way:

<items>
<field type="field">field1</field>
<field type="text">whatever the customer wants between the combined fields</field>
<field type="field">field2</field>
<field type="text">whatever the customer wants between/after the combined fields</field>
<field type="field">field3</field>
</items>

an example of this xml would translate to:

<field1>, <field2> and <field3> or <field1>+<field2>=<field3>

In my xslt I have this:

<xsl:variable name="configfile" select="document(myconfigxml.xml)"/>

Then I use xslt to loop over the field types and where the @type=’field’ I want to use the value of the field to look into the element of the source xml.

<xsl:template name="items">
    <xsl:param name="personElementFromSourceXml"/>
    <xsl:for-each select="$configfile/items/field">
        <xsl:choose>
            <xsl:when test="@type='field'">
                <xsl:value-of select="???"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="."/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:for-each>
</xsl:template>

What would I need to type on the place of the ??? ? In pseudo-xslt it would be $personElementFromSourceXml/value-of-<field1-2-3>
I tried a number of things, such as concat($personElementFromSourceXml, ‘/’, current()), tried $personElementFromSourceXml/current(), but they don’t work.

Also, small sanity check here: Is my idea of tackling this problem an okay approach or am I violating every rule in the book? Note, I’m still new to xslt.

  • 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-23T11:34:16+00:00Added an answer on May 23, 2026 at 11:34 am

    You’ve got the right idea, namely selecting the element whose content you by means of the value of its name. Forgive me if I misunderstood your question, but I interpreted the ‘items’ file as a template file and assumed a separate input file. E.g. for the config file:

    <items>
      <field type="text">Here are the contents of bark: </field>
      <field type="field">bark</field>
      <field type="text">Here are the contents of woof: </field>
      <field type="field">woof</field>
      <field type="text">The end of the line.
    </field>
    </items>
    

    and for the source file:

    <file>
      <woof>Woof! Woof!</woof>
      <meow>Meow.</meow>
      <bark>Bark! Bark!</bark>
    </file>
    

    I adapted your code thus:

    <?xml version="1.0"?>
    
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="text"/>
      <xsl:variable name="configfile" select="document('config.xml')"/>
      <xsl:variable name="srcfile" select="/"/>
    
      <xsl:template match="/">
        <xsl:for-each select="$configfile/items/field">
          <xsl:choose>
            <xsl:when test="@type='field'">
              <xsl:variable name="tagname" select="."/>
              <xsl:value-of select="$srcfile/descendant::*[local-name()=$tagname]"/>
              <xsl:text>
    </xsl:text>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="."/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>
      </xsl:template>
    
    </xsl:stylesheet>
    

    Because the xsl:for-each is iterating over $configfile/items/field, each field element becomes the context node, so you need a way of explicitly referring to the source file, which is why I assign it to a global variable. I get this output:

    Here are the contents of bark: Bark! Bark!
    Here are the contents of woof: Woof! Woof!
    The end of the line.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How does one access data imported from a CSV file by using dynamic note
How does one create Dynamic CSS and JavaScript On-The-Fly (using PHP). This needs to
How does one convert an image from one color profile to another (screen to
How does one do this? If I want to analyze how something is getting
Does any one know how I can specify the Default value for a DateTime
I have a problem to get the highest Value in a dynamic List of
does one perform better over the other in terms of indexing/quering etc ? e.g.
How does one go about authoring a Regular Expression that matches against all strings
How does one go about referencing a class's static properties in xaml? In other
How does one go about programatically building a TemplateColumn object and adding it 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.