根据xml的内容使用java或xslt分割xml [英] Splitting an xml based on the contents of xml either using java or xslt

查看:164
本文介绍了根据xml的内容使用java或xslt分割xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,考虑下面的xml数据
Input1.xml

I have a requirement,consider the below xml data Input1.xml

 <Envelope>
    <Notification>
    <Data>
    <Input>ABCDEFGHIJKLMN</Input>
    <Output>RESPONSEDATA</Output>
    </Data>
  <Data>
    <Input>OPQRSTUVWXYZ</Input>
    <Output>NEXTDATA</Output>
    </Data>
  <Data>
    <Input>ALPHABETS</Input>
    <Output>SOMEDATA</Output>
    </Data>
    </Notification>
    </Envelope>

现在我需要3个输出xmls的响应,如下面的文件名所示,前面有6个字符的ABCDEFGHIJKLMN作为输出文件名,如下所示:

Now I want 3 output xmls with the response as shown below the file name to have first 6 characters ofABCDEFGHIJKLMN as output file name to have as shown below

(FILE1)->ABCDEF.XML
    <Output>RESPONSEDATA</Output>
(FILE2)->OPQRST.XML

    <Output>NEXTDATA</Output>
(FILE3)->ALPHAB.XML
 <Output>SOMEDATA</Output>


推荐答案

您使用哪种XSLT 1.0处理器? Xalan Java支持

Which XSLT 1.0 processor do you use? Xalan Java supports

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0"
    xmlns:redirect="http://xml.apache.org/xalan/redirect"
    extension-element-prefixes="redirect"
    exclude-result-prefixes="redirect">


  <xsl:template match="/Envelope/Notification/Data[not(Input/*)]">
    <redirect:write select="concat(substring(Input, 1, 6), '.xml')">
      <xsl:copy-of select="Output"/>
    </redirect:write>
  </xsl:template>

  <xsl:template match="/Envelope/Notification/Data[Input/*]">
    <redirect:write select="concat(local-name(Input/*), '.xml')">
      <xsl:copy-of select="Output"/>
    </redirect:write>
  </xsl:template>

</xsl:stylesheet>

这篇关于根据xml的内容使用java或xslt分割xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆