【问题标题】:How to create Session id in xml with the help of XSLT如何在 XSLT 的帮助下在 xml 中创建 Session id
【发布时间】:2014-07-22 04:34:52
【问题描述】:

我的预期 XML 输出(我需要使用 XSLT 转换的 XML。):

 <DST>
 <DST>
 <PQAWD>
<username>TEST</username> 
<password>Test</password> 
<newPassword /> 
<hostAddress>@@@@@@@@@@</hostAddress> 
<hostPort>@@@@@</hostPort> 
</PQAWD>
</DST>
 <AWDLogon>
<userID>TEST</userID> 
<password encrypt="Y">TRST</password> 
<hostAddress>test</hostAddress> 
<hostPort>@@@@@</hostPort> 
<trace /> 
<readable>N</readable> 
<timeout>120000</timeout> 
<newPassword encrypt="Y" /> 
<config userPrivileges="Y" options="Y" sendRequest="Y" /> 
<currentJobName>PQAWDLogon</currentJobName> 
</AWDLogon>
**<tidx>48006c7898e61461eb110f66a714629864ocx$388111915602261781664778</tidx>** 
</DST>

XSL 表(要添加哪个元素以获得以上输出)..

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version = "1.0">
<xsl:template match="//DST/PQAWD">
<AWDLogon>
<userID><xsl:valueof select="username"/></userID>
<password encrypt="Y"><xsl:valueof select="password"/></password>
<hostAddress><xsl:valueof select="hostAddress"/></hostAddress>
<hostPort><xsl:valueof select="hostPort"/></hostPort>
<trace></trace>
<readable>N</readable>
<timeout>120000</timeout>
<newPassword encrypt="Y"><xsl:valueof select="newPassword"/></newPassword>
<config userPrivileges="Y" options="Y" sendRequest="Y" />
<currentJobName>PQAWDLogon</currentJobName> 
</AWDLogon>
</xsl:template>
</xsl:stylesheet>

上面是XML,&lt;tidx&gt;标签应该像动态改变的会话ID一样, 是否有任何程序或标签要添加到当前 XSLT 表中以获取上述 XML 作为输出,请帮助我(请考虑上面的 xsl 表作为参考)...

【问题讨论】:

  • 您使用的是 XSLT 1.0 还是 2.0?如果是 XSLT 1.0,具体是哪个处理器?
  • 很抱歉问你,如何找出我的 xsl 被哪个进程使用?,我是 xml 和 xslt 文件的新手...请帮助我..
  • 您将如何运行(执行)转换?
  • 我正在使用这个网站进行转换freeformatter.com/xsl-transformer.html#ad-output,但在内部我无法得到它是如何处理的以及是哪个过程,如果我错了请建议我......
  • michael.hor257k,你知道吗?

标签: xml spring xslt spring-integration


【解决方案1】:

Spring 集成&lt;int-xml:xslt-transformer&gt; 支持&lt;int-xml:xslt-param&gt;。您可以向 XSLT 模板提供任何变量:

<int-xml:xslt-transformer input-channel="xsltChannel"
                              output-channel="output"
                              xsl-resource="classpath:myTemplate.xslt">
     <int-xml:xslt-param name="sessionId" expression="[ANY_VALID_SPEL_HERE]"/>
</int-xml:xslt-transformer>

你的 xslt 应该有这个:

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:param name="sessionId"/>

    <xsl:template match="//DST/PQAWD">
            ....
           <tidx>
              <xsl:value-of select="$sessionId" />
           </tidx>
    </xsl:template>
</xsl:stylesheet>

更多信息在这里:http://docs.spring.io/spring-integration/docs/latest-ga/reference/html/xml.html#xml-transformer-namespace

【讨论】:

  • [Headers={timestamp=1401709356294,id=6a83b09e-f874-2d51-b016-106584460372,correlationId=e7d46888-4697-0669-3ab6-6cf4112509bb,jobDesignerJobName=PQASWDLogon,序列DT77214Passwd@1, sequenceNumber=1}] 这是标题部分,我需要用表达式=“[ANY_VALID_SPEL_HERE]”替换它,请你帮忙..
  • 首先你应该解释一下sessionId在你的情况下是什么。使用消息头中唯一的id 可能就足够了。这是您的域,我们无法确定业务逻辑
  • 我已经尝试过使用“header.jobDesignerJobName”,但是我得到了像 这样的空标签,我需要把它放在上面定义的标题部分中..
  • session id 表示每次登录都会产生的随机数,例如:48006c7898e61461eb110f66a714629864ocx$388111915602261781664778
  • 好吧。只需生成它并放在 XSLT 之前的消息头
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-11-11
  • 1970-01-01
  • 2011-02-20
  • 1970-01-01
  • 2019-12-01
  • 1970-01-01
  • 2017-01-22
相关资源
最近更新 更多