程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何使用附加的 if 条件从 xml 中删除行大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决如何使用附加的 if 条件从 xml 中删除行?

开发过程中遇到如何使用附加的 if 条件从 xml 中删除行的问题如何解决?下面主要结合日常开发的经验,给出你关于如何使用附加的 if 条件从 xml 中删除行的解决方法建议,希望对你解决如何使用附加的 if 条件从 xml 中删除行有所启发或帮助;

我有两个 xml 文件。 首先是一个 config.xml 文件:

      <values>
   <s1>yes</s1>
   <s2>no</s2>
   <s3>yes</s3>
   <s4>no</s4>
</values>

第二个是 @H_707_3@my_input.xml 文件,我想通过 xslt 转换它:

<?xml version="1.0"?>
<aaa>  
  <bbb>  
      <code>Code</code>
      <name1>1111</name1>
      <name2>2222</name2>
      <documents xsi:nil="true"/>
      <xi:include href="s1.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
      <xi:include href="s2.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
      <xi:include href="s3.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
      <xi:include href="s4.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
  </bbb>
</aaa>

Output.xml 文件应如下所示:

<?xml version="1.0"?>
<aaa>  
  <bbb>  
      <code>Code</code>
      <name1>1111</name1>
      <name2>2222</name2>
      <documents xsi:nil="true"/>
      <xi:include href="s1.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
      <xi:include href="s3.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
  </bbb>
</aaa>

如果 confing.xml 文件中的“no”字符串将被分配,则应从 @H_707_3@my_input.xml 文件中删除该行。

您可以在下面找到我的代码。但是我只能删除单独的行,但我不确定如何添加额外的IF条件...你有什么想法吗?

<?xml version="1.0"?>
<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/1999/XSL/transform"
  xmlns:xsi="http://www.w3.org/2001/XMLscheR_939_11845@a-instance" 
  version="1.0">

  <xsl:output omit-xml-declaration="no" indent="yes"/>
  <xsl:Strip-space elements="*"/>

  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates SELEct="node()|@*"/>
    </xsl:copy>
  </xsl:template>   

  <xsl:template match="*[@href = 's2.xml']" />
  <xsl:template match="*[@href = 's4.xml']" />
</xsl:stylesheet>

溴, 溶胶

解决方法

使用

<xsl:template match="xi:include[document('config.xml')/values/*[. = 'no' and local-name() = subString-before(current()/@href,'.')]]"/>

大佬总结

以上是大佬教程为你收集整理的如何使用附加的 if 条件从 xml 中删除行全部内容,希望文章能够帮你解决如何使用附加的 if 条件从 xml 中删除行所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。