以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  想通过xslt判断xml中的元素进行相应的类型划分  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=60971)


--  作者:自由风
--  发布时间:4/6/2008 5:59:00 PM

--  想通过xslt判断xml中的元素进行相应的类型划分
输入文件input.xml:
<?xml version="1.0" encoding="UTF-8"?>
<requestinfo>
 <VSITEID>1000000000000234</VSITEID>
 <CERCs>
  <CERC>181</CERC>
  <CERC>182</CERC>
 </CERCs>
 <VPN>108</VPN>
 <SR>219</SR>
</requestinfo>


想得到的out.xml:
<?xml version="1.0" encoding="UTF-8"?>
<requestinfo>
 <data>
  <type>1</type>
  <VSITEID>1000000000000234</VSITEID>
  <LOCATOR_ID>181</LOCATOR_ID>
 </data>
 <data>
  <type>1</type>
  <VSITEID>1000000000000234</VSITEID>
  <LOCATOR_ID>182</LOCATOR_ID>
 </data>
 <data>
  <type>2</type>
  <VSITEID>1000000000000234</VSITEID>
  <LOCATOR_ID>108</LOCATOR_ID>
 </data>
 <data>
  <type>3</type>
  <VSITEID>1000000000000234</VSITEID>
  <LOCATOR_ID>219</LOCATOR_ID>
 </data>
</requestinfo>


其中要根据元素的名称进行类型的划分,比如:元素为CERC,type=1;元素为VPN,type=2;元素为SR,type=3;

有那位大哥能帮我看看xslt怎么写?我已经想了一整天了想不出来,头痛。。。


--  作者:Qr
--  发布时间:4/6/2008 7:20:00 PM

--  
自己完成吧,
<data>
 <type>
  <xsl:choose>
   <xsl:when test="name()='CERC'">1</xsl:when>
   <xsl:when test="name()='VPN'">2</xsl:when>
   <xsl:when test="name()='SR'">3</xsl:when>
  </xsl:choose>
 </type>
 <xsl:copy-of select="../../VSITEID|../VSITEID"/>
 <LOCATOR_ID><xsl:value-of select="." /></LOCATOR_ID>
</data>
--  作者:自由风
--  发布时间:4/7/2008 1:37:00 PM

--  
太感谢Qr大哥,我在论坛上问了几个问题,基本上都是Qr大哥帮我解决的,小弟在这说声:多谢!该问题根据大哥的提示解决了。
--  作者:Qr
--  发布时间:4/7/2008 4:31:00 PM

--  
我是论坛的受益者,趁着还有精力,现在是我回报论坛的时候了。
--  作者:自由风
--  发布时间:4/8/2008 11:14:00 AM

--  
Qr大哥,还有一个问题想请教你
我的xslt如下:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:CIM">
 <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
 <xsl:template match="/">
  <code>
   <xsl:for-each select="properties/item">
    <xsl:choose>
     <xsl:when test="name = 'State'">
      <xsl:choose>
       <xsl:when test="value='DEPLOYED' or value='FUNCTIONAL'">0</xsl:when>
       <xsl:when test="value='INVALID' or value='FAILED_AUDIT'">1</xsl:when>
       <xsl:when test="value='REQUESTED' or value='PENDING'">2</xsl:when>
      </xsl:choose>
     </xsl:when>
    </xsl:choose>
   </xsl:for-each>
  </code>
 </xsl:template>
</xsl:stylesheet>

我用XMLSpy软件单步调试没有任何问题,将其部署到servicemix中,运行报错如下:

Error at element constructor <responseinfo> of :
  XPTY0004: Cannot compare xs:string to xs:integer
ERROR - SaxonComponent                 - Error processing exchange InOut[
  id: ID:demo-36723-1207365059684-202:2
  status: Active
  role: provider
  service: {http://www.zznode.com/vpndis}request-response-format
  endpoint: endpoint
  in: <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns0="http://www.cisco.com/cim-cx/2.0" xmlns:ns1="urn:CIM" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Header>
    <ns0:message id="87855" sessiontoken="39B21CBF68406FD013635474DA8F0276" timestamp="2008-04-08T02:24:40.201Z" wait="true" waittimeout="90"/>
  </soapenv:Header>

SystemID: ; Line#: -1; Column#: -1
net.sf.saxon.trans.DynamicError: Cannot compare xs:string to xs:integer
        at net.sf.saxon.expr.ValueComparison.compare(ValueComparison.java:586)
        at net.sf.saxon.expr.GeneralComparison.compare(GeneralComparison.java:570)
        at net.sf.saxon.expr.GeneralComparison.effectiveBooleanValue(GeneralComparison.java:490)
        at net.sf.saxon.instruct.Choose.processLeavingTail(Choose.java:325)
        at net.sf.saxon.instruct.Choose.processLeavingTail(Choose.java:338)
        at net.sf.saxon.instruct.Choose.processLeavingTail(Choose.java:338)
        at net.sf.saxon.instruct.Block.processLeavingTail(Block.java:353)
        at net.sf.saxon.instruct.Choose.processLeavingTail(Choose.java:338)
        at net.sf.saxon.instruct.Instruction.process(Instruction.java:91)
        at net.sf.saxon.instruct.ForEach.processLeavingTail(ForEach.java:244)
        at net.sf.saxon.instruct.Block.processLeavingTail(Block.java:353)
        at net.sf.saxon.expr.LetExpression.processLeavingTail(LetExpression.java:352)
        at net.sf.saxon.instruct.Choose.processLeavingTail(Choose.java:338)
        at net.sf.saxon.instruct.Instruction.process(Instruction.java:91)
        at net.sf.saxon.instruct.ForEach.processLeavingTail(ForEach.java:244)
        at net.sf.saxon.instruct.Instruction.process(Instruction.java:91)
        at net.sf.saxon.instruct.ElementCreator.processLeavingTail(ElementCreator.java:250)
        at net.sf.saxon.instruct.Block.processLeavingTail(Block.java:353)
        at net.sf.saxon.instruct.Instruction.process(Instruction.java:91)
        at net.sf.saxon.instruct.ElementCreator.processLeavingTail(ElementCreator.java:250)
        at net.sf.saxon.instruct.Block.processLeavingTail(Block.java:353)
        at net.sf.saxon.instruct.Instruction.process(Instruction.java:91)
        at net.sf.saxon.instruct.ElementCreator.processLeavingTail(ElementCreator.java:250)
        at net.sf.saxon.instruct.Instruction.process(Instruction.java:91)
        at net.sf.saxon.instruct.ForEach.processLeavingTail(ForEach.java:244)
        at net.sf.saxon.instruct.Template.applyLeavingTail(Template.java:99)
        at net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:319)
        at net.sf.saxon.Controller.transformDocument(Controller.java:1602)
        at net.sf.saxon.Controller.transform(Controller.java:1426)
        at org.apache.servicemix.saxon.XsltEndpoint.transformContent(XsltEndpoint.java:97)
        at org.apache.servicemix.saxon.XsltEndpoint.transform(XsltEndpoint.java:74)
        at org.apache.servicemix.saxon.SaxonEndpoint.processInOut(SaxonEndpoint.java:201)
        at org.apache.servicemix.common.endpoints.ProviderEndpoint.process(ProviderEndpoint.java:109)
        at org.apache.servicemix.common.AsyncBaseLifeCycle.doProcess(AsyncBaseLifeCycle.java:489)
        at org.apache.servicemix.common.AsyncBaseLifeCycle.processExchange(AsyncBaseLifeCycle.java:441)
        at org.apache.servicemix.common.BaseLifeCycle.onMessageExchange(BaseLifeCycle.java:46)
        at org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.processInBound(DeliveryChannelImpl.java:593)
        at org.apache.servicemix.jbi.nmr.flow.AbstractFlow.doRouting(AbstractFlow.java:174)
        at org.apache.servicemix.jbi.nmr.flow.seda.SedaFlow.doRouting(SedaFlow.java:176)
        at org.apache.servicemix.jbi.nmr.flow.seda.SedaQueue$1.run(SedaQueue.java:134)
        at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)
        at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
        at java.lang.Thread.run(Thread.java:595)


--  作者:自由风
--  发布时间:4/8/2008 11:17:00 AM

--  
主要的错误在于:XPTY0004: Cannot compare xs:string to xs:integer

我在网上查了半天也没有想到相应的资料

只好请教一下大哥了!


--  作者:Qr
--  发布时间:4/9/2008 10:17:00 AM

--  
应该是数据类型不匹配的问题,具体检查XSL中的@test部分。
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
78.125ms