English 中文(简体)
xslt, how to selected tags, based on the content of another same level tag
原标题:xslt, how to select tags, based on the contents of another same level tag
  • 时间:2010-09-27 16:11:50
  •  标签:
  • xslt

我的消息来源认为:

<stuff> 
<s>
    <contents>
      <code>503886</code>
      <code>602806</code>
    </contents>
    ...
</s>
<p>
    <code>344196</code>
    <export>true</export>
    ...
</p>
<!-- more  s  and  p  tags -->
...
</stuff>

我需要重复和选择这些内容——在内容标语中,有一条属于具有出口效力的纸张。

I ve been trying to solve this for the last couple of hours. Please share some ideas.

最佳回答

这一风格:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:key name="kSByCode" match="s" use="contents/code"/>
    <xsl:template match="text()"/>
    <xsl:template match="p[export= true ]">
        <xsl:copy-of select="key( kSByCode ,code)"/>
    </xsl:template>
</xsl:stylesheet>

加上这一投入:

<stuff>
    <s>
        <contents>
            <code>503886</code>
            <code>602806</code>
        </contents>
    </s>
    <p>
        <code>602806</code>
        <export>true</export>
    </p>
</stuff>

产出:

<s>
    <contents>
        <code>503886</code>
        <code>602806</code>
    </contents>
</s>

<>说明/指示>:只要有交叉参考资料,就使用钥匙。

<>Edit:小姐在<代码><>/代码>部分上填满。 感谢 Dimitre!

。 我在阅读这一答案时认为,这可能令人困惑。 因此,关于“的表述 a. 使用:

key( kSByCode ,/stuff/p[export= true ]/code)
问题回答

I need to iterate over s and choose those - which inside contents tag have a code that belongs to a p that has export=true.

<>Use:

<xsl:apply-templates select=
 "/*/s
      [code
      =
       /*/p
          [export= true ]
                      /code]"/>




相关问题
When test hanging in an infinite loop

I m tokenising a string with XSLT 1.0 and trying to prevent empty strings from being recognised as tokens. Here s the entire function, based on XSLT Cookbook: <xsl:template name="tokenize"> ...

quick xslt for-each question

Let s say I have an XML document that has this: <keywords> <keyword>test</keyword> <keyword>test2</keyword> <keyword>test3</keyword> <keyword>test4</...

XSLT Transform XML with Namespaces

I m trying to transform some XML into HTML using XSLT. Problem: I can t get it to work. Can someone tell me what I m doing wrong? XML: <ArrayOfBrokerage xmlns:i="http://www.w3.org/2001/...

XSLT output to HTML

In my XSLT file, I have the following: <input type="button" value= <xsl:value-of select="name">> It s an error as it violates XML rule. What I actually want is having a value from an ...

Mangling IDs and References to IDs in XML

I m trying to compose xml elements into each other, and the problem I am having is when there s the same IDs. Basically what I need to do is mangle all the IDs in an xml file, as well as the ...

Sharepoint 2007 Data view Webpart custom parameters

I m sort of new to the custom parameters that can be setup on a DataView Webpart. There are 6 options: - None - Control - Cookie - Form - QueryString - Server Variable I think that None, Cookie and ...

热门标签