简体   繁体   中英

How to store the input xml data in to map using XSLT2.0

I'm tring to store the input xml data into map and how to save that data.

Input XML:

    <person>
     <value id="123">
        <name>abc</name>
        <age>25</age>
    </value>
    <value id="456">
        <name>xyz</name>
        <age>80</age>
    </value>
    <value id="1235">
        <name>abcfg</name>
        <age>25</age>
    </value>
    <value id="4568">
        <name>xyzd</name>
        <age>80</age>
    </value>
    </person>

Output File:

xyzd|80
abcfg|25

Is there any way to possible to store the data into map object and print that data into output?

Given this input XML,

<person>
  <value id="123">
    <name>abc</name>
    <age>25</age>
  </value>
  <value id="456">
    <name>xyz</name>
    <age>80</age>
  </value>
  <value id="1235">
    <name>abcfg</name>
    <age>25</age>
  </value>
  <value id="4568">
    <name>xyzd</name>
    <age>80</age>
  </value>
</person>

the following XSLT, which will work with both XSLT 2.0 and 1.0,

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="value">
    <xsl:value-of select="concat(name,'|',age,'&#xa;')"/>
  </xsl:template>

</xsl:stylesheet>

will produce a mapping output file,

abc|25
xyz|80
abcfg|25
xyzd|80

of the format requested.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM