Xslt dynamic value

How to make a dynamic value?

In this case:

1) We get XML export from system A.
2) We select and format some data that is necessary for system B.
3) One of the transferred fields should be combined from several elements of the original xml.

Combined items can be customized by the client.

So now I have the following:
XSLT for converting xml from system A A
simple xml configuration where the client can specify the fields that he wants to combine in series:

<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 will 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 @type = 'field' I want to use the field value to find the element of the original 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>

???? pseudo-xslt $personElementFromSourceXml/value-of-<field1-2-3> , concat ($ personElementFromSourceXml, '/', current()), $personElementFromSourceXml/current(), .

, : , ? , xslt.

+3
1

, , . , , "items" . . :

<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>

:

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

:

<?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>

xsl:for-each $configfile/items/field, field node, , , :

Here are the contents of bark: Bark! Bark!
Here are the contents of woof: Woof! Woof!
The end of the line.
0

All Articles