使用 XSLT 删除 XML 中的父节点 [英] Deleting parent nodes in XML using XSLT

查看:31
本文介绍了使用 XSLT 删除 XML 中的父节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助使用 XSLT 从下面给定的 XML 中删除父节点..

I need help in removing parent nodes from below given XML using XSLT..

<?xml version="1.0" encoding="UTF-8"?>
<Report xmlns="OpenProblems2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="OpenProblems2" Name="OpenProblems2">
   <Hello>
      <NewDataSet>
         <Table>
            <a>1832874</a>
            <b>HUME-9063</b>
            <c>not informed</c>
         </Table>
         <Table>
            <a>1832874</a>
            <b>HUME-9063</b>
            <c>not informed</c>
         </Table>
      </NewDataSet>
   </Hello>
</Report>

输出应该看起来像 -

<NewDataSet>
<Table>
  <a>1832874</a> 
  <b>HUME-9063</b> 
  <c>not informed</c>
</Table>
<Table>
  <a>1832874</a> 
  <b>HUME-9063</b> 
  <c>not informed</c>
</Table>
</NewDataSet>

XSLT 应该删除 Report,Hello &新数据集元素.请...您的帮助将不胜感激.

XSLT should remove Report,Hello & NewDataset elements. please... your help will be highly appreciated.

推荐答案

如果你想保持命名空间不变,那么你只需要

If you want to leave the namespace as it is, then all you need is

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

    <xsl:template match="/">
        <xsl:copy-of select="o:NewDataSet"/>
    </xsl:template>

</xsl:stylesheet>

这篇关于使用 XSLT 删除 XML 中的父节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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