xslt 语法简单应用及调试方法

公司用到应用集成平台,有webservice适配器,用起来还算方便,其中会接触到xslt的语法

维基百科的解释:

http://zh.wikipedia.org/wiki/XSLT

就是根据模板将XML 报文转换成MML串(a=1,b=2,c=3),

语法到也算简单,不过开始调试的时候很费力,后来发现 XMLSPY工具非常好用,下面就介绍下使用方法。

 

 

1.       首先编辑好xslt配置文件(附录1)

2.       选择转换,或者按F10

 

3.       选择需要解析的xml文件

 

4.       查看解析后的输出文件

 

结果为:head=|||userid=ID1||userid=ID2|userid=test,

 

5.     如果需要的话还可以进行单步调试,快捷键F11

6.       可以查看定义的变量值以及调用堆栈。

方便快捷的应用集成平台,但缺少灵活性。

 

 

附录1:转换的xslt文件

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xalan="http://xml.apache.org/xalan" version="2.0">

       <xsl:output method="text"/>

       <xsl:strip-space elements="*"/>

       <xsl:template match="/">

              <xsl:variable name="userid" select="text()"/>

              <xsl:variable name="tmpkey" select="text()"/>

              <xsl:variable name="tmpvalue" select="text()"/>

              <xsl:variable name="outstr" select="'userid='"/>

              <xsl:text>head=</xsl:text>

              <xsl:for-each select="//response/body/values/object/parameter">

                     <!-->

                     <xsl:value-of select="/appField"/>

                     <xsl:value-of select="/FieldValue"/>                  

                     <-->

                     <xsl:variable name="index1" select="position()"/>

                     <xsl:if test="compare(appField,'userid')=0">

                            <xsl:variable name="userid" select="FieldValue"/>

                            <xsl:variable name="tmpkey" select="appField"/>

                            <xsl:variable name="outstr" select="concat($outstr,$userid)"/>

                            <xsl:value-of select="$outstr"/>

      

                     </xsl:if>

                     <xsl:if test="$index1!=last()">

                            <xsl:text>|</xsl:text>

                     </xsl:if>

              </xsl:for-each>

             

              <xsl:variable name="outstr" select="concat($outstr,'test')"/>

              <xsl:value-of select="$outstr"/>

 

              <xsl:text>,</xsl:text>

       </xsl:template>

</xsl:stylesheet>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值