以文本方式查看主题

-  中文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=37262)


--  作者:zhouzz
--  发布时间:8/27/2006 8:14:00 PM

--  哪位兄弟帮我过滤一下数据?
源数据:
<?xml version="1.0" encoding="GBK"?>
<outputlist>
<output>
<managedElement.ManagedElement_T>
  <name>
    <globaldefs.NameAndStringValue_T>
      <name>EMS</name>
      <value>Huawei/T2000-2</value>
    </globaldefs.NameAndStringValue_T>
    <globaldefs.NameAndStringValue_T>
      <name>ManagedElement</name>
      <value>33554433</value>
    </globaldefs.NameAndStringValue_T>
  </name>
  <userLabel></userLabel>
  <nativeEMSName>清江2</nativeEMSName>
  <owner></owner>
  <location></location>
  <version>0.0.0.1</version>
  <productName>OptiX DWDM OLA</productName>
  <communicationState>
    <value>0</value>
  </communicationState>
  <emsInSyncState>true</emsInSyncState>
  <supportedRates/>
  <additionalInfo/>
</managedElement.ManagedElement_T>
<managedElement.ManagedElement_T>
  <name>
    <globaldefs.NameAndStringValue_T>
      <name>EMS</name>
      <value>Huawei/T2000-2</value>
    </globaldefs.NameAndStringValue_T>
    <globaldefs.NameAndStringValue_T>
      <name>ManagedElement</name>
      <value>33554434</value>
    </globaldefs.NameAndStringValue_T>
  </name>
  <userLabel></userLabel>
  <nativeEMSName>台州2</nativeEMSName>
  <owner></owner>
  <location></location>
  <version>0.0.0.1</version>
  <productName>OptiX DWDM OLA</productName>
  <communicationState>
    <value>0</value>
  </communicationState>
  <emsInSyncState>true</emsInSyncState>
  <supportedRates/>
  <additionalInfo/>
</managedElement.ManagedElement_T>
</output>
</outputlist>

目标数据:
<?xml version="1.0" encoding="GB2312"?>
<resource>
<dataclass name="adm">
<userLabel/>
<nativeEMSName>清江2</nativeEMSName>
<owner/>
<location/>
<version>0.0.0.1</version>
<productName>OptiX DWDM OLA</productName>
<communicationState>0</communicationState>
<emsInSyncState>true</emsInSyncState>
<supportedRates/>
<ems>Huawei/T2000-2</ems>
<objectName>Huawei/T2000-2,33554433</objectName>
</dataclass>
</resource>

中间的xslt怎么写啊?在线等待中~~~


--  作者:zhouzz
--  发布时间:8/30/2006 11:31:00 AM

--  
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs">
 <xsl:output method="xml" encoding="gb2312" indent="yes"/>
 <xsl:template match="/outputlist/output">
  <xsl:for-each select="managedElement.ManagedElement_T">
     <resource>
          <dataclass name="adm">
         <xsl:copy-of select="userLabel"/>
    <xsl:copy-of select="nativeEMSName"/>
    <xsl:copy-of select="owner"/>
                <xsl:copy-of select="location"/>
                <xsl:copy-of select="version"/>
                <xsl:copy-of select="productName"/>
                <xsl:copy-of select="commsunicationState"/>
                <xsl:copy-of select="emsInSyncState"/>
                <xsl:copy-of select="supportedRates"/>
                <ems><xsl:value-of select="./name/globaldefs.NameAndStringValue_T/value[1]"/></ems>
                <objectName></objectName>
                </dataclass>
      </resource>
  </xsl:for-each>
 </xsl:template>
</xsl:stylesheet>

objectname那段怎么写?


--  作者:sam
--  发布时间:8/30/2006 1:44:00 PM

--  

          <objectName>
            <xsl:for-each select="./name/globaldefs.NameAndStringValue_T">
              <xsl:if test="position() > 1">
                <xsl:text>,</xsl:text>
              </xsl:if>
              <xsl:value-of select="value"/>
            </xsl:for-each>
          </objectName>
--  作者:zhouzz
--  发布时间:8/30/2006 4:08:00 PM

--  
我去试一下,万分感谢这位兄弟!
--  作者:zhouzz
--  发布时间:8/30/2006 4:36:00 PM

--  
可以用的!谢谢!!!
如果<globaldefs.NameAndStringValue_T>值大于2个,是n个
而不仅仅把第一,第二个value值合在一起,需要要随意组吗话有什么方法吗?
如值1和值2,值2和值3,值1和值4,等等~~
position() > 1 能有更多的定义吗?
(不好意思我自己没试,就来网上问。。现在就去试了)


--  作者:zhouzz
--  发布时间:8/30/2006 5:04:00 PM

--  
<xsl:value-of select="./name/globaldefs.NameAndStringValue_T/value[1]"/>
有人和我说value[1]是第一个值,[2]的话是最第二个值,再用concat连接一下,但是就是取不到第二个值
--  作者:sam
--  发布时间:8/30/2006 5:22:00 PM

--  
那个能取到第二个值就怪了

<xsl:value-of select="./name/globaldefs.NameAndStringValue_T[2]/value"/>


--  作者:zhouzz
--  发布时间:8/30/2006 5:30:00 PM

--  
实际情况是要写3个xslt,
一个里面是2个值,要求值(1,2), 您已经解决了,
第二个里面有4个值,要求值(1,2),(1,2,3),(1,2,3,4),(1,2,3,4--1,2,3,4)
第三个里面有3个值(1,2),(1,2,3)
--  作者:zhouzz
--  发布时间:8/31/2006 10:18:00 AM

--  
使用concat涵数后,循环应该怎么写啊?
现在每次都只是将第一组的值相连接,第二组也是用第一组的值
--  作者:sam
--  发布时间:8/31/2006 10:27:00 AM

--  
你参照这个改一下,这个应该可以满足你的第三种要求
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs">
  <xsl:output method="xml" encoding="gb2312" indent="yes"/>
  <xsl:template match="/outputlist/output">
    <xsl:for-each select="managedElement.ManagedElement_T">
      <resource>
        <dataclass name="adm">
          <xsl:copy-of select="userLabel"/>
          <xsl:copy-of select="nativeEMSName"/>
          <xsl:copy-of select="owner"/>
          <xsl:copy-of select="location"/>
          <xsl:copy-of select="version"/>
          <xsl:copy-of select="productName"/>
          <xsl:copy-of select="commsunicationState"/>
          <xsl:copy-of select="emsInSyncState"/>
          <xsl:copy-of select="supportedRates"/>
          <ems>
            <xsl:value-of select="./name/globaldefs.NameAndStringValue_T[2]/value"/>
          </ems>
          <objectName>
            <xsl:call-template name="third-multiple">
              <xsl:with-param name="count" select="4"/>
            </xsl:call-template>
          </objectName>
        </dataclass>
      </resource>
    </xsl:for-each>
  </xsl:template>
  <xsl:template name="third-multiple">
    <xsl:param name="count" select="2"/>
    <xsl:choose>
      <xsl:when test="$count = 2">
        <xsl:call-template name="third-single">
          <xsl:with-param name="count2" select="$count"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="third-multiple">
          <xsl:with-param name="count" select="$count -1"/>
        </xsl:call-template>
        <xsl:call-template name="third-single">
          <xsl:with-param name="count2" select="$count"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template name="third-single">
    <xsl:param name="count2" select="2"/>
    <xsl:text>(</xsl:text>
    <xsl:for-each select="./name/globaldefs.NameAndStringValue_T">
      <xsl:if test="position() &lt; $count2+1">
        <xsl:if test="position() > 1">
          <xsl:text>,</xsl:text>
        </xsl:if>
        <xsl:value-of select="value"/>
      </xsl:if>
    </xsl:for-each>
    <xsl:text>)</xsl:text>
  </xsl:template>
</xsl:stylesheet>

--  作者:zhouzz
--  发布时间:8/31/2006 2:50:00 PM

--  
3个值的前提下,前2个值相连接分别对应是哪一段?能说明一下吗?
3个值的前提下,3个值相连用您说的第一个方法可以实现的


[此贴子已经被作者于2006-8-31 16:22:51编辑过]

--  作者:sam
--  发布时间:8/31/2006 4:20:00 PM

--  

//的前面要加点

以下是引用zhouzz在2006-8-31 14:50:00的发言:
3个值的前提下,前2个值相连接分别对应是哪一段?能说明一下吗?
3个值的前提下,3个值相连用您说的第一个方法可以实现的

xsl:value-of select="concat(.//globaldefs.NameAndStringValue_T[1]/value, ', ',.//globaldefs.NameAndStringValue_T[2]/value)" /
这样连接出来每次都是第一组的值






--  作者:zhouzz
--  发布时间:8/31/2006 5:44:00 PM

--  
可以了,又出现个新问题
我要取一个值的部分,我查了资料,说要用string before涵数,
如:
<value>/rack=1/shelf=1/slot=5/port=1</value>
只要需要<value>/rack=1/shelf=1/slot=5/</value>

substring-before("/rack=1/shelf=1/slot=5/port=1","/port"),可以用的

我用concat('a',',' 'b')和
select=".//globaldefs.NameAndStringValue_T/value取到值,然后<xsl:text>,</xsl:text>,再加上另一个值,是一样的?

[此贴子已经被作者于2006-9-1 9:49:52编辑过]

W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
156.250ms