2011-01-26 83 views
0

我遇到了xsl映射器的性能问题。 下面是一些例子XSL(注:真正的XSL这样下去,10万行)xsl性能问题

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var" version="1.0" xmlns:ns3="http://microsoft.com/HealthCare/HL7/2X/2.3.1/Tables" xmlns:ns4="http://microsoft.com/HealthCare/HL7/2X/2.3.1/DataTypes" xmlns:ns0="http://microsoft.com/HealthCare/HL7/2X/2.3.1/Segments" xmlns:ns2="http://microsoft.com/HealthCare/HL7/2X" xmlns:ns1="http://Cegeka.C2M.Accelerator.Schemas.segments_C2M"> 
<xsl:output omit-xml-declaration="yes" method="xml" version="1.0" /> 
<xsl:template match="/"> 
    <xsl:apply-templates select="/ns2:ADT_231_GLO_DEF" /> 
</xsl:template> 
<xsl:template match="/ns2:ADT_231_GLO_DEF"> 
<ns2:ADT_231_GLO_DEF> 
    <xsl:for-each select="EVN_EventType"> 
    <EVN_EventType> 
     <xsl:if test="normalize-space(EVN_1_EventTypeCode/text())"> 
     <EVN_1_EventTypeCode> 
      <xsl:value-of select="EVN_1_EventTypeCode/text()" /> 
     </EVN_1_EventTypeCode> 
     </xsl:if> 
     <EVN_2_RecordedDateTime> 
     <xsl:if test="normalize-space(EVN_2_RecordedDateTime/TS_0_TimeOfAnEvent/text())"> 
      <TS_0_TimeOfAnEvent> 
      <xsl:value-of select="EVN_2_RecordedDateTime/TS_0_TimeOfAnEvent/text()" /> 
      </TS_0_TimeOfAnEvent> 
     </xsl:if> 
     </EVN_2_RecordedDateTime> 
     <xsl:for-each select="EVN_3_DateTimePlannedEvent"> 
     <xsl:if test="normalize-space(TS_0_TimeOfAnEvent/text())"> 
      <EVN_3_DateTimePlannedEvent> 
      <TS_0_TimeOfAnEvent> 
       <xsl:value-of select="TS_0_TimeOfAnEvent/text()" /> 
      </TS_0_TimeOfAnEvent> 
      </EVN_3_DateTimePlannedEvent> 
     </xsl:if> 
     </xsl:for-each> 
     <xsl:if test="normalize-space(EVN_4_EventReasonCode/text())"> 
     <EVN_4_EventReasonCode> 
      <xsl:value-of select="EVN_4_EventReasonCode/text()" /> 
     </EVN_4_EventReasonCode> 
     </xsl:if> 
    </EVN_EventType> 
    </xsl:for-each> 
    </ns2:ADT_231_GLO_DEF> 
    </xsl:template> 
    </xsl:stylesheet> 

那么,我做的是:

- I copy the nodes I want from the source xml 
- I don't copy the empty nodes or the nodes that contain a break (hence why I check normalize-space(/text()) 

现在的执行时间是约1秒,这是正常的吗?我在biztalk中使用这种映射,通常每秒可以处理至少10条消息(如果不是更多:p),但是这个映射会造成延迟,所以我每秒只能处理1条消息:(

现在我是没有一个xsl大师不幸的是,如果任何人可以给我一些建议,这是值得欢迎的:)

THX

+0

您不会说源邮件的大小是多少:这将是决定执行时间的主要因素。你也不会说你如何衡量执行时间 - 你是否包含XML解析时间?您通常可以通过确定执行时间是线性变化还是(比如说)以源文档大小的二次方式获得有用的诊断信息 - 也就是说,如果大小加倍,则经过时间会增加2倍或4倍或更差?如果它是二次的,那么通常可以通过正确使用xsl:key来解决问题。 – 2011-01-26 10:43:50

+0

虽然没有真正解决你的问题w.r.t.性能,还有一些'可爱的'递归XSLT模板匹配算法来一般地去掉空的节点 - 这可以为你节省很多编码吗?例如http://www.stylusstudio.com/xsllist/200403/post50690.html – StuartLC 2011-01-26 10:56:45

回答

2

我复制节点,我从源XML要

我不要复制空节点或包含中断的节点(因此我检查归一化空间)

第一个,我建议你可以使用带有覆盖的身份转换。例如,下面的代码将复制所有元素,但不包括那些“在空白(在空白标准化后)字符串值并且没有子元素或属性”的元素。

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="xml" indent="yes"/> 

<xsl:template match="@* | node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@* | node()"/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="*[not(normalize-space()) and not(*) and not(@*)]"/> 

</xsl:stylesheet> 

,你可以尝试,通过剥离在编译时未使用空格:

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

这样你的文件会保存在不显着空格内存中,因此会更简洁。