以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  [求助]如何在转换后消除相同项  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=45952)


--  作者:wystan
--  发布时间:4/25/2007 12:44:00 AM

--  [求助]如何在转换后消除相同项
求助各位老大
比如我的原文档
<start>
   <element>
       <name>1</name>
       <class>a</class>
   </element>
   <element>
       <name>2</name>
       <class>a</class>
   </element>
   <element>
       <name>3</name>
       <class>a</class>
   </element>
   <element>
       <name>4</name>
       <class>b</class>
   </element>
</start>
转换后的效果
<start>
    <class>a
        <name>1</name>
        <name>2</name>
        <name>3</name>
        <name>4</name>
    </class>
    <class>b
        <name>5</name>    
    </class>   
</start>  

大概就是这个意思 要把新文档按照原文档中的class归类 合并后显示出来 不知道如何利用xslt来实现 多谢各位 谁能帮看看写个例子xslt


--  作者:hexun831012
--  发布时间:4/25/2007 9:11:00 AM

--  
转换两次
--  作者:wystan
--  发布时间:4/25/2007 1:19:00 PM

--  
如何转换两次 老大 能否说的再详细点....
--  作者:gogy
--  发布时间:4/25/2007 9:19:00 PM

--  
试试:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="start">
  <xsl:copy select=".">
   <xsl:for-each select="element[not(preceding-sibling::element/class=class)]">
    <xsl:copy select="class">
     <xsl:value-of select="class"/>
     <xsl:copy-of select="../element[class=current()/class]/name"/>
    </xsl:copy>
   </xsl:for-each>
  </xsl:copy>
 </xsl:template>
</xsl:stylesheet>
--  作者:gogy
--  发布时间:4/25/2007 9:48:00 PM

--  
sorry 出现了概念错误。<xs:copy>那里。
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="start">
  <xsl:copy select=".">
   <xsl:for-each select="element[not(preceding-sibling::element/class=class)]/class">
    <xsl:copy>
     <xsl:value-of select="."/>
     <xsl:copy-of select="//element[class=current()]/name"/>
    </xsl:copy>
   </xsl:for-each>
  </xsl:copy>
 </xsl:template>
</xsl:stylesheet>

--  作者:wystan
--  发布时间:4/26/2007 2:42:00 AM

--  
先感谢再研究
--  作者:wystan
--  发布时间:4/26/2007 10:36:00 PM

--  
When I use the same function I can't get the result.
I try a lot but I don't why it doesnot work
my original text  

it is structure is like
<MSRFR>
   <FR-FEATURES>
        <FR-FEATURE ID="">
           ...
            <FR-FMEA-INFO>
                <FM-STRUCTURE-ELEMENT-REFS>
                    <FM-STRUCTURE-ELEMENT-REF/>
              ...      
        <FR-FEATURE ID="">
        <FR-FEATURE ID="">
         .....
   </FR-FEATURES>
</MSRFR>

I want transfer it to the structure as
<FM-STRUCTURE-ELEMENTS>
   <FM-STRUCTURE-ELEMENT ID="">
       <FM-SE-FEATURES>
            <FM-FEATURE ID-REF=""/>
            <FM-FEATURE ID-REF=""/>
             ....
   <FM-STRUCTURE-ELEMENT ID="">
   <FM-STRUCTURE-ELEMENT ID="">
    ...
<FM-STRUCTURE-ELEMENTS>

and i write the xslt like
<xsl:template match="/">
   <FM-STRUCTURE-ELEMENTS>
       <xsl:for-each select="MSRFR/FR-FEATURES/FR-FEATURE[not(following-sibling::FR-FEATURE/FR-FMEA-INFO/FM-STRUCTURE-ELEMENT-REFS/FM-STRUCTURE-ELEMENT-REF=FM-STRUCTURE-ELEMENT-REF)]/FR-FMEA-INFO/FM-STRUCTURE-ELEMENT-REFS/FM-STRUCTURE-ELEMENT-REF">
       <xsl:element name="FM-STRUCTURE-ELEMENT">
          <xsl:attribute name="ID">
              <xsl:value-of select="."/>
          </xsl:attribute>
          <xsl:copy-of select="//FR-FEATURE[//FM-STRUCTURE-ELEMENT-REF=current()]/@ID"/>
         </xsl:element>        </xsl:for-each>
   </FM-STRUCTURE-ELEMENTS>

but the results show all structure elements
...


--  作者:gogy
--  发布时间:4/27/2007 12:07:00 AM

--  
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
   <FM-STRUCTURE-ELEMENTS>
    <xsl:for-each select="MSRFR/FR-FEATURES/FR-FEATURE/FR-FMEA-INFO/FM-STRUCTURE-ELEMENT-REFS/FM-STRUCTURE-ELEMENT-REF[not(preceding::FM-STRUCTURE-ELEMENT-REF=.)]">
       <xsl:element name="FM-STRUCTURE-ELEMENT">
          <xsl:attribute name="ID">
              <xsl:value-of select="."/>
          </xsl:attribute>
          <!--xsl:copy-of select="//FR-FEATURE[//FM-STRUCTURE-ELEMENT-REF=current()]/@ID"/-->
         </xsl:element>        
   </xsl:for-each>
   </FM-STRUCTURE-ELEMENTS>
</xsl:template>
</xsl:stylesheet>
备注的那句话,不知道你要干嘛。为什么把属性ID覆盖了呢?
另:下次能用中文描述问题吗?
--  作者:wystan
--  发布时间:4/27/2007 12:18:00 AM

--  
不好意思 白天找不到中文输入 想先发出去
就是说不知道为什么我用你的方法 我感觉基本都是照搬了 可是输出里面还是把所有的
structure element 都输出了 没有把相同的消除掉 觉得很奇怪
--  作者:wystan
--  发布时间:4/27/2007 12:29:00 AM

--  
问题基本就是我一开始问得 就是节点深了些 不知道问题出在哪里
原文档中按各个特点排列的 FR-FEATURE 然后有个属性ID纪录名字 后面又有个属性<FM-STRUCTURE-ELEMENT-REF>这里记录它的结构元素

然后我想把它转换成按结构元素排列的 <FM-STRUCTURE-ELEMENT 然后他也有个属性ID存名字 再在每个结构元素里列出有哪些特点<FM-FEATURE ID-REF=""/><FM-FEATURE ID-REF=""/>这里的ID-REF存 FR-FEATURE里的ID

我按照你的方法可是输出来以后还是把所有的结构元素都列出来了
所以我想可能是<xsl:for-each select="element[not(preceding-sibling::element/class=class)]/class">这句判别的时候出了问题 我试过你的没有问题 可是用到我这里就不知道怎么回事了
我的这句是
<xsl:for-each select="MSRFR/FR-FEATURES/FR-FEATURE[not(following-sibling::FR-FEATURE/FR-FMEA-INFO/FM-STRUCTURE-ELEMENT-REFS/FM-STRUCTURE-ELEMENT-REF=FM-STRUCTURE-ELEMENT-REF)]/FR-FMEA-INFO/FM-STRUCTURE-ELEMENT-REFS/FM-STRUCTURE-ELEMENT-REF">


--  作者:gogy
--  发布时间:4/27/2007 12:43:00 AM

--  
呵呵,我已经写了新代码啊。在上面那里。
--  作者:gogy
--  发布时间:4/27/2007 12:44:00 AM

--  
我已经发了新的代码啊,在上面那里。
有一个地方,我不知道你要干嘛,所以备注了代码啊
--  作者:gogy
--  发布时间:4/27/2007 12:47:00 AM

--  
很多东西,不能照搬啊,建议你看看XPATH的轴,就明白了。
--  作者:wystan
--  发布时间:4/27/2007 2:39:00 PM

--  
wo jue de zhu yao jiu shi wo bu zhi dao zai XSLT li mian shen me bian liang huo zhe dai ma neng gou chu cun yi jing shu chu guo de StructureElement
suo yi wo bu zhi dao na ge tiao jian yu ju ru he lai xie
zai ci gan xie bang zhu
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
83.984ms