English 中文(简体)
当XSLT供餐时,就有一个 lo。 我怎么能够根据其他十种反洗钱法的价值,对这一十种反洗钱法作出归属或回避。 USING XLT
原标题:When XSLT for-each is in a loop. How can I add an attribute or node to that XML based on other XML value. USING XSLT
  • 时间:2011-04-25 06:21:04
  •  标签:
  • xml
  • xslt

谁能帮助我解答这一问题?

我有XML,并根据某些条件过滤这些数值。 将过滤的xml放在一个变量中。 在过滤条件时,Im试图在过滤的xml上添加一个属性或 no子,但不是为我工作。

投入XML:

    <root>
        <a id="13">
            <b>XXX1</b>
            <c>YYY1</c>
        </a>
        <a id="2">
            <b>XXX2</b>
            <c>YYY2</c>
        </a>
        <a id="15">
            <b>XXX3</b>
            <c>YYY3</c>
        </a>
        <a id="37">
            <b>XXX4</b>
            <c>YYY4</c>
        </a>
        <a id="51">
            <b>XXX5</b>
            <c>YYY5</c>
        </a>
    </root>

另一种XML储存在一个称为“数据”的变量中(用于过滤):

<sample>
    <con id="37" order="1"/>
    <con id="13" order="2"/>
    <con id="51" order="3"/>
    <con id="2" order="4"/>
    <con id="15" order="5"/>
</sample>

使用XSLT,I m试图过滤和安放;以这种方式增加一个元素。

<xsl:variable name="filteredData">
    <newroot>
      <xsl:for-each select="/root/a[@id > 14]">
        <xsl:if test="msxsl:node-set($data)/sample/con[@id = current()/@id]/@id = current()/@id">
          <xsl:element name="order">
            <xsl:value-of select="msxsl:node-set($data)/sample/con[@id = current()/@id]/@order"/>
          </xsl:element>
        </xsl:if>
      </xsl:for-each>
    </newroot>
</xsl:variable>

OUTPUT XML (i.e., "filteredData" variable should contain below XML):

     <newroot>
        <a id="15">
            <b>XXX3</b>
            <c>YYY3</c>
            <order>5</order>
        </a>
        <a id="37">
            <b>XXX4</b>
            <c>YYY4</c>
            <order>1</order>
        </a>
        <a id="51">
            <b>XXX5</b>
            <c>YYY5</c>
            <order>3</order>
        </a>
    </newroot>
最佳回答
问题回答

在投入的基础上,我现在尝试了并实施了另一种代表形式。

《新锡索托法》:

<xsl:variable name="filteredData">        
    <newroot>          
      <xsl:for-each select="/root/a[@id > 14]">
        <xsl:copy>
          <xsl:copy-of select="@*|node()"/>
          <xsl:element name="Order">
            <xsl:choose>
              <xsl:when test="msxsl:node-set($data)/sample/con[@id = current()/@id]/@id = current()/@id">
                <xsl:value-of select="msxsl:node-set($data)/sample/con[@id = current()/@id]/@order"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:text>&#160;</xsl:text>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:element>
        </xsl:copy>
      </xsl:for-each>
    </newroot>
  </xsl:variable>




相关问题
how to represent it in dtd?

I have two element action and guid. guid is a required field when action is add. but when action is del it will not appear in file. How to represent this in dtd ?

.Net application configuration add xml-data

I need to add xml-content to my application configuration file. Is there a way to add it directly to the appSettings section or do I need to implement a configSection? Is it possible to add the xml ...

XStream serializing collections

I have a class structure that I would like to serialize with Xstream. The root class contains a collection of other objects (of varying types). I would like to only serialize part of the objects that ...

MS Word splits words in its XML format

I have a Word 2003 document saved as a XML in WordProcessingML format. It contains few placeholders which will be dynamically replaced by an appropriate content. But, the problem is that Word ...

Merging an XML file with a list of changes

I have two XML files that are generated by another application I have no control over. The first is a settings file, and the second is a list of changes that should be applied to the first. Main ...

How do I check if a node has no siblings?

I have a org.w3c.dom.Node object. I would like to see if it has any other siblings. Here s what I have tried: Node sibling = node.getNextSibling(); if(sibling == null) return true; else ...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

热门标签