0

My requirement is to do a XML A to XML B transformation. The Tag in which I read from XML A should be configurable, it is a kind of iteartion of lists. If there is any new tag present in XML A, it should be dealt by adding entries in configuration file for Java and programatically which in turn should be reflected in XSLT and transformed to XML B.

I'm using Java. Is it possible by passing parameters? as my requirement need the parameters are passed in a loop or a List.

I'm new to XSLT and any info link on this would be very much appreciated.

Source XML - There can be more like yearly, weekly etc here

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Report>
    <Daily>
        <input>1234</input>
    </Daily>
    <Monthly>
        <input>8678</input>
    </Monthly>  
</Report>

Target XML

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Report>
    <Value>
        <Attribute>
            <name>Daily</name>
            <values>1234</values>
        </Attribute>
        <Attribute>
            <name>Monthly</name>
            <values>8678</values>
        </Attribute>
    </Value>
</Report>
gaborsch
  • 15,408
  • 6
  • 37
  • 48
Benny R
  • 9
  • 3
  • Can you provide an example or A which you want to get to B and example of B .. – Kenneth Clark Aug 25 '14 at 13:16
  • Disagree. This question is not asking for any external resource, it defines a clear target, and asking for help how to get to the solution. Obviously OP had no information about some features like `name()` function, otherwise it complies all SO standards. – gaborsch Aug 26 '14 at 12:26

1 Answers1

1

You can use the name() or the local-name() function for the currently selected node.

See how to selecting current element name in XSLT

Here's the sketch of the code:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/Report/">
        <Value>
        <xsl:for-each select="*">
            <Attribute>
                <name>
                    <xsl:value-of select="name()"/>
                </name>
                <values>
                    <xsl:value-of select="./input"/>
                </values>
            </Attribute>
        </xsl:for-each>
        </Value>
    </xsl:template>
</xsl:stylesheet>
Community
  • 1
  • 1
gaborsch
  • 15,408
  • 6
  • 37
  • 48