尝试根据元素值选择节点

时间:2017-02-22 14:24:56

标签: xslt

我有一个文件,如下所示。 我需要处理文件并根据元素值= CT复制节点。我有点失去了如何或从哪里开始。任何帮助将不胜感激。

样式表:

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
    >
      <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

      <xsl:template match="/">
        <feed>
          <xsl:for-each select="web-export/run-date/pub-code/ad-type">
            <xsl:copy-of select="."/>
          </xsl:for-each>
        </feed>
      </xsl:template>
    </xsl:stylesheet>

XML:

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<web-export>
<run-date>02/01/2017
<pub-code>News
<ad-type>Legal Liner
<cat-code>Legals</cat-code>
<class-code>Legal</class-code>
<subclass-code>Briefings</subclass-code>
<placement-description></placement-description>
<position-description></position-description>
<subclass3-code></subclass3-code>
<subclass4-code></subclass4-code>
<order-number>0000023456</order-number>
<FieldedDataSet>
<State>CT</State>
</FieldedDataSet>
<ad-content><![CDATA[Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque est. ]]></ad-content>
</ad-type>
</pub-code>
<pub-code>News
<ad-type>Legal Liner
<cat-code>Legals</cat-code>
<class-code>Legal</class-code>
<subclass-code>Notices</subclass-code>
<ad-number>0000012345</ad-number>
<FieldedDataSet>
<State>RI</State>
</FieldedDataSet>
<ad-content><![CDATA[Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque est. ]]></ad-content>
</ad-type>
</pub-code>
</run-date>
</web-export>

1 个答案:

答案 0 :(得分:0)

如果任何子元素具有value =“CT”

,则有效
int function(int a[*])