Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用XSLT过滤XML元素_Xslt - Fatal编程技术网

使用XSLT过滤XML元素

使用XSLT过滤XML元素,xslt,Xslt,假设我有以下XML输入文件: <root> <NodeX> ... </NodeX> <NodeY> ... </NodeY> <Description> <section01> <subsection key="KeyA">Some text</subsection> <s

假设我有以下XML输入文件:

<root> 
  <NodeX> 
      ... 
  </NodeX>  
  <NodeY> 
      ... 
  </NodeY>  
  <Description>
      <section01>
         <subsection key="KeyA">Some text</subsection>
         <subsection key="KeyB">Some text</subsection>
      </section1>

      <section02>
         <subsection key="KeyC">Some text</subsection>
      </section2>

      <section03>
         <subsection key="KeyD">Some Text</subsection>
      </section3>

   </Description>  
   ...
</root>

... 
... 
一些文本
一些文本
一些文本
一些文本
...
以及另一个带有“规则”的XML文件,其中子部分的键与访问群体属性一起列出

示例摘录:

<rules>
    <subsection id="01">
        <key audience="internalOnly">KeyA</key>
        <key audience="internalOnly">KeyB</key>
    </subsection>

    <subsection id="02">
        <key>KeyC</key>
    </subsection>
<rules>

凯亚
钥匙
凯克
我尝试编写一个XSL转换,根据规则XML填充中的访问群体属性值从输入XML文件中删除子部分。如果该值为“internalOnly”,则必须删除该小节

在本例中,应产生以下输出XML:

<root> 
  <NodeX> 
      ... 
  </NodeX>  
  <NodeY> 
      ... 
  </NodeY>  
  <Description>
      <section02>
         <subsection key="KeyC">Some text</subsection>
      </section2>

      <section03>
         <subsection key="KeyD">Some Text</subsection>
      </section3>

   </Description>  
   ...
</root>

... 
... 
一些文本
一些文本
...
(整个第01节被删除,因为这两个小节都是“内部的”)

问题是1)规则XML文件中的“查找”和2)如果删除了所有相应的子节,则删除节元素:

如果输入XML文件中包含访问群体属性,我将为需求创建以下XSLT:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="subsection[@audience='internalOnly']"></xsl:template>
</xsl:stylesheet>

我看不出这和你的有什么大区别。如果要从rules.xml文档中排除某些键,请将
keys
变量的定义更改为:

<xsl:variable name="keys" select="key" />

致:


其他一切都可以保持原样


在理解XSLT键函数的用法时遇到问题


这是一个非常值得研究的问题。

别忘了添加当前的XSL。。。这与您之前的问题有什么不同:stackoverflow.com/questions/22663044/rule-based-restruction-of-nodes/我之前问题中的节点重新排列是此处删除过程的某种先决条件。我想将删除步骤与重新排列步骤分开。我试图在您前面的答案的基础上编写XSL转换:stackoverflow.com/questions/22663044/rule-based-restruction-of-nodes/,但在理解XSLT键函数的用法时遇到了问题。XSLT键函数的使用是否适合我在此处删除所需的查找?
<xsl:variable name="keys" select="key[not(@audience='internalOnly')]" />