English 中文(简体)
将某些儿童降为新的孙子
原标题:Move certain child nodes down to a new grandchild level
  • 时间:2010-09-03 00:25:42
  •  标签:
  • xml
  • xslt

我已经找到了其他问题,即把 no子上传入母子,但Im没有把trick落到新产生的 no子。

鉴于:

<Villain>
  <Name>Dr Evil</Name>
  <Age>49</Age>
  <Like>Money</Like>
  <Like>Sharks</Like>
  <Like>Lasers</Like>
</Villain>

我试图用锡克尔特公司来改变这一局面:

<Villain>
  <Name>Dr Evil</Name>
  <Age>49</Age>
  <Likes>
    <Like>Money</Like>
    <Like>Sharks</Like>
    <Like>Lasers</Like>
  </Likes>
</Villain>

换言之,插入一个新的儿童节点,并将所有称为“Like”的儿童节点移至此处。

最佳回答

www.un.org/Depts/DGACM/index_spanish.htm 这一转变:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

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

  <xsl:template match="Like[1]">
   <Likes>
    <xsl:apply-templates select="../Like" mode="copy"/>
   </Likes>
  </xsl:template>

   <xsl:template match="*" mode="copy">
    <xsl:call-template name="identity"/>
   </xsl:template>
   <xsl:template match="Like"/>
 </xsl:stylesheet>

在应用XML文件时:

<Villain>
  <Name>Dr Evil</Name>
  <Age>49</Age>
  <Like>Money</Like>
  <Like>Sharks</Like>
  <Like>Lasers</Like>
</Villain>

<produces the Hope,那末正确结果:

<Villain>
   <Name>Dr Evil</Name>
   <Age>49</Age>
   <Likes>
      <Like>Money</Like>
      <Like>Sharks</Like>
      <Like>Lasers</Like>
   </Likes>
</Villain>

  1. www.un.org/Depts/DGACM/index_spanish.htm 身份规则的使用和否决。

  2. www.un.org/Depts/DGACM/index_spanish.htm 使用modes来具体规定某种不同的处理方式。

问题回答

暂无回答




相关问题
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

热门标签