Вопрос

I have this source and target : enter image description here

I need that my map would produce a target with 2 nodes of "T".

The first one is with "A" source content, and the second is with "B" source content.

For example:

Input:

<Root>
 <A>
   <FieldA>FA</FieldA>
   <FieldB>FB</FieldB>
 </A>
 <B>
   <FieldC>FC</FieldC>
   <FieldD>FD</FieldD>
 </B>
</Root>

Requested Output:

<Root>
    <T>
      <F1>FA</F1>
      <F2>FB</F1>
    </T>
    <T>
      <F1>FC</F1>
      <F2>FD</F2>
    </T>   
</Root>

*** There is also a condition regarding the map from "B" to "T"

Это было полезно?

Решение

Place looping functoid

A --> Looping Functoid --> T
B --> Looping Functoid --> T

FieldA --> F1
FieldB --> F2
FieldC --> F1
FieldD --> F2

Другие советы

The following does what you want to achieve:

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

<xsl:output method="xml" indent="yes"/>

 <xsl:template match="/">
  <xsl:apply-templates/>
 </xsl:template>

 <xsl:template match="Root">
  <xsl:copy>
   <xsl:apply-templates/>
  </xsl:copy>
 </xsl:template>

 <xsl:template match="A|B">
  <xsl:element name="T">
    <xsl:apply-templates/>
  </xsl:element>
 </xsl:template>

 <xsl:template match="*[parent::A or parent::B]">
  <xsl:choose>
     <xsl:when test="./name() = 'FieldA' or ./name() = 'FieldC'">
        <xsl:element name="F1">
           <xsl:value-of select="."/>
        </xsl:element>
     </xsl:when>
     <xsl:otherwise>
        <xsl:element name="F2">
           <xsl:value-of select="."/>
        </xsl:element>
     </xsl:otherwise>
  </xsl:choose>
 </xsl:template>

</xsl:stylesheet>

Besides, please take the time to report on what you have tried so far. SO is not there to do your homework. So, show your effort in your future questions.

Just link A and B to T through a Looping Functoid.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top