根据匹配条件将XML元素的内容从1修改为5? [英] Modify XML element content(s) from 1 to 5 based on matching criteria(s)?

查看:58
本文介绍了根据匹配条件将XML元素的内容从1修改为5?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题需要根据简单的匹配条件(匹配数字1)替换XML中的值。

This question requires replacement of values in an XML based on simple matching criteria (matches number 1).

条件:用于匹配TrackNumber 1到5的项目):

    FOR <ScannedTrack>
            WHERE <TrackNumber>1 or 2 or 3 or 4 or 5
IF <Codec>2048</Codec>

    OUTPUT/WRITE
          <Encoder>Ac3Passthrough</Encoder>



编辑



我简化了这个问题并简化了XML文件,以便可以正确测试答案。

Edit

I have simplifed this question and simplified the XML file so that answers can be correctly tested.

推荐答案

如果要将XML转换为其他XML,而剩下的部分在根据条件转换某些节点时保持不变,然后使用身份转换模板启动XSLT(在XSLT 3中可以通过声明< xsl:mode on-no-match = shallow-复制 /> ),然后添加与要转换的节点匹配的模板,以便您的前三个条件可以转换为

If you want to transform XML to another XML where leaving parts unchanged while transforming some nodes based on conditions then you start the XSLT with the identity transformation template (which in XSLT 3 can be conveniently expressed simply by declaring <xsl:mode on-no-match="shallow-copy"/>) and then add templates matching the nodes you want to transform so your first three conditions might translate into

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="#all"
    version="3.0">

  <xsl:mode on-no-match="shallow-copy"/>

  <xsl:template match="AudioTrack[ScannedTrack[Codec = (65536, 1111)]]/Encoder">
      <xsl:copy>AacPassthru</xsl:copy>
  </xsl:template>

  <xsl:template match="AudioTrack[ScannedTrack[Codec = 2222]]/Encoder">
      <xsl:copy>Mp3PassthruEncoderTool</xsl:copy>
  </xsl:template>  

  <xsl:template match="AudioTrack[ScannedTrack[Codec = 3333]]/Encoder">
      <xsl:copy>Passthrough</xsl:copy>
  </xsl:template>

</xsl:stylesheet>

由于无法提供符合条件的示例数据,因此无法进行测试。

It is not possible to test that as you failed to provide any sample data matching your conditions.

这篇关于根据匹配条件将XML元素的内容从1修改为5?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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