公司用到应用集成平台,有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>