xslt中的多个命名空间 [英] Multiple namespace in xslt

查看:145
本文介绍了xslt中的多个命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是XML / XSLT的新手。我的任务是在下面的结构中生成xml并通过ASP.NET应用程序发送它的restful服务器。你能帮我在VS2010中使用XSLT生产下面的结构吗?在此先感谢。

所需的输出XML:

Hi all, I'm new to XML/ XSLT. My task is to generate xml in the below structure and send it restful server through ASP.NET application. Could you help me to produce the below structure using XSLT in VS2010 please? Thanks in advance.
Required output XML:

<?xml version="1.0" encoding="UTF8"?>
<MyTalkTalkMessage xmlns="http://www.Testwebsite.com/xx/dunlop" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" 

               xmlns:gt="http://www.Testwebsite.com/schemas/freetalk/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"               

               xsi:schemaLocation="http://www.Testwebsite.com/xx/dunlop http://xmlws.Testwebsite.com/v10/schema/Etalk_mychapter.xsd">
  <dunlopVersion>1.0</dunlopVersion>
  <dunHeader>
    <dunMessageDetails>
      <dunClass>ClassName</dunClass>     
    </dunMessageDetails>    
  </dunHeader>  
  <Body>
    <MyTestSubmit xmlns="http://xmlws.Testwebsite.com/MyHeader" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

                    xsi:schemaLocation="http://xmlws.Testwebsite.com/Header http://xmlws.Testwebsite.com/v123/schema/wsforms/MyTestFormSubmit.xsd"

                    xmlns:bs="http://xmlws.Testwebsite.com">      
      <myDateSig>19990102</myDateSig>
      <Form>
        <myPets xmlns="http://xmlws.Testwebsite.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

                      xsi:schemaLocation="http://xmlws.Testwebsite.com http://xmlws.Testwebsite.com/v123/schema/wsforms/myPetreturn342.xsd">                  
          <Pets>
            <petCompCode>1234</petCompCode>
          </Pets>
          <PetVETAddress>
            <VetPetAddress>Address</VetPetAddress>                      
          </PetVETAddress>          
        </myPets>
      </Form>
    </MyTestSubmit>
  </Body>
</MyTalkTalkMessage>



在我的xslt中,我已经包含了所有的命名空间,但是当转换为xslt时,xml已被包含生成没有


In my xslt, I have included all the namespaces but when transformed the xslt, the xml has been generated without

xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance 

in

<mytestsubmit>  & <mypets>

我的输出部分xml

我的xslt:

sections of my output xml
My xslt:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" omit-xml-declaration="no"/>  
  <xsl:template match="/">
    <xsl:apply-templates select="/Test" />
  </xsl:template>
  <xsl:template match="Test">
	<MyTalkTalkMessage xmlns="http://www.Testwebsite.com/xx/dunlop" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" 

               xmlns:gt="http://www.Testwebsite.com/schemas/freetalk/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"               

               xsi:schemaLocation="http://www.Testwebsite.com/xx/dunlop http://xmlws.Testwebsite.com/v10/schema/Etalk_mychapter.xsd">
	
	<dunlopVersion>1.0</dunlopVersion>
  	<dunHeader>
    		<dunMessageDetails>
      			<dunClass><xsl:value-of select="Test/dunClass"/></dunClass>      			
    		</dunMessageDetails>    		
  	</dunHeader>  	    
      <Body>
        <MyTestSubmit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

			xmlns:bs="http://xmlws.Testwebsite.com"

			xsi:schemaLocation="http://xmlws.Testwebsite.com/Header http://xmlws.Testwebsite.com/v123/schema/wsforms/MyTestFormSubmit.xsd"			xmlns="http://xmlws.Testwebsite.com/MyHeader">		
      		<myDateSig>
			<xsl:variable name="dts" select="Test/SigDate"/>
            		<xsl:value-of select="concat(substring($dts, 1, 4), '-',
                      		substring($dts, 6, 2), '-', substring($dts, 9, 2))"/>
		</myDateSig>          
          <Form>
            <myPets xmlns="http://xmlws.Testwebsite.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

                      xsi:schemaLocation="http://xmlws.Testwebsite.com http://xmlws.Testwebsite.com/v123/schema/wsforms/myPetreturn342.xsd">
          <Pets>
            <petCompCode><xsl:value-of select="Test/CompCode"/></petCompCode>
          </Pets>
          <PetVETAddress>
            <VetPetAddress><xsl:value-of select="Test/Add1"/></VetPetAddress>                   
          </PetVETAddress>
        </myPets>
      </Form>
    </MyTestSubmit>
  </Body>
</MyTalkTalkMessage>
</xsl:template>
</xsl:stylesheet>





C#代码:



C# code:

{
            XslCompiledTransform myXslTrans = new XslCompiledTransform();            myXslTrans.Load(HttpContext.Current.Server.MapPath("~/Test/InputXSLT.xslt"));            myXslTrans.Transform(HttpContext.Current.Server.MapPath("~/Test/OutputXML.xml"), myXMLPath + "\\" + xmlFileName);
        }



我的输出XML


My output XML

<?xml version="1.0" encoding="UTF-8"?>
<MyTalkTalkMessage xmlns="http://www.Testwebsite.com/xx/dunlop" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" 

               xmlns:gt="http://www.Testwebsite.com/schemas/freetalk/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"               

               xsi:schemaLocation="http://www.Testwebsite.com/xx/dunlop http://xmlws.Testwebsite.com/v10/schema/Etalk_mychapter.xsd">
  <dunlopVersion>1.0</dunlopVersion>
  <dunHeader>
    <dunMessageDetails>
      <dunClass>ClassName</dunClass>     
    </dunMessageDetails>    
  </dunHeader>  
  <Body>
    <MyTestSubmit xmlns="http://xmlws.Testwebsite.com/MyHeader" 

                  xsi:schemaLocation="http://xmlws.Testwebsite.com/Header http://xmlws.Testwebsite.com/v123/schema/wsforms/MyTestFormSubmit.xsd"

                  xmlns:bs="http://xmlws.Testwebsite.com">
      <myDateSig>19990102</myDateSig>     
      <Form>
        <myPets xmlns="http://xmlws.Testwebsite.com"  

                xsi:schemaLocation="http://xmlws.Testwebsite.com http://xmlws.Testwebsite.com/v123/schema/wsforms/myPetreturn342.xsd">
          <Pets>
            <petCompCode>1234</petCompCode>
          </Pets>
          <PetVETAddress>
            <VetPetAddress>Address</VetPetAddress>                      
          </PetVETAddress>          
        </myPets>
      </Form>
    </MyTestSubmit>
  </Body>
</MyTalkTalkMessage>





Could you advise me how to generate a required output xml please? TIA.



Could you advise me how to generate a required output xml please? TIA.

推荐答案

dts, 1, 4), '-',
\t\tsubstring(
dts, 1, 4), '-', substring(


dts, 6, 2), '-', substring(
dts, 6, 2), '-', substring(


dts, 9, 2))\"/>
\t\t</myDateSig>
<Form>
<myPets xmlns=\"http://xmlws.Testwebsite.com\" xmlns:xsi=\"http: //www.w3.org/2001/XMLSchema-instance\"

xsi:schemaLocation=\"http://xmlws.Testwebsite.com http://xmlws.Testwebsite.com/v123/schema/wsforms/myPetreturn342.xsd\">
<Pets>
<petCompCode><xsl:value-of select=\"Test/CompCode\"/></petCompCode>
</Pets>
<PetVETAddress>
<VetPetAddress><xsl:value-of select=\"Test/Add1\"/></VetPetAddress>
</PetVETAddress>
</myPets>
</Form>
</MyTestSubmit>
</Body>
</MyTalkTalkMessage>
</xsl:template>
</xsl:stylesheet >
dts, 9, 2))"/> </myDateSig> <Form> <myPets xmlns="http://xmlws.Testwebsite.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlws.Testwebsite.com http://xmlws.Testwebsite.com/v123/schema/wsforms/myPetreturn342.xsd"> <Pets> <petCompCode><xsl:value-of select="Test/CompCode"/></petCompCode> </Pets> <PetVETAddress> <VetPetAddress><xsl:value-of select="Test/Add1"/></VetPetAddress> </PetVETAddress> </myPets> </Form> </MyTestSubmit> </Body> </MyTalkTalkMessage> </xsl:template> </xsl:stylesheet>





C# code:



C# code:

{
            XslCompiledTransform myXslTrans = new XslCompiledTransform();            myXslTrans.Load(HttpContext.Current.Server.MapPath("~/Test/InputXSLT.xslt"));            myXslTrans.Transform(HttpContext.Current.Server.MapPath("~/Test/OutputXML.xml"), myXMLPath + "\\" + xmlFileName);
        }



My output XML


My output XML

<?xml version="1.0" encoding="UTF-8"?>
<MyTalkTalkMessage xmlns="http://www.Testwebsite.com/xx/dunlop" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" 

               xmlns:gt="http://www.Testwebsite.com/schemas/freetalk/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"               

               xsi:schemaLocation="http://www.Testwebsite.com/xx/dunlop http://xmlws.Testwebsite.com/v10/schema/Etalk_mychapter.xsd">
  <dunlopVersion>1.0</dunlopVersion>
  <dunHeader>
    <dunMessageDetails>
      <dunClass>ClassName</dunClass>     
    </dunMessageDetails>    
  </dunHeader>  
  <Body>
    <MyTestSubmit xmlns="http://xmlws.Testwebsite.com/MyHeader" 

                  xsi:schemaLocation="http://xmlws.Testwebsite.com/Header http://xmlws.Testwebsite.com/v123/schema/wsforms/MyTestFormSubmit.xsd"

                  xmlns:bs="http://xmlws.Testwebsite.com">
      <myDateSig>19990102</myDateSig>     
      <Form>
        <myPets xmlns="http://xmlws.Testwebsite.com"  

                xsi:schemaLocation="http://xmlws.Testwebsite.com http://xmlws.Testwebsite.com/v123/schema/wsforms/myPetreturn342.xsd">
          <Pets>
            <petCompCode>1234</petCompCode>
          </Pets>
          <PetVETAddress>
            <VetPetAddress>Address</VetPetAddress>                      
          </PetVETAddress>          
        </myPets>
      </Form>
    </MyTestSubmit>
  </Body>
</MyTalkTalkMessage>





Could you advise me how to generate a required output xml please? TIA.



Could you advise me how to generate a required output xml please? TIA.


这篇关于xslt中的多个命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆