开发者

xsl performance issue

I am having trouble with the performance of an xsl mapper. Here is some example xsl (note: the real xsl goes on like this for 10 000 lines)

<?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">
        <开发者_StackOverflow社区;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>

So what I am doing is:

- 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())

Now the execution time is about 1 second, is this normal? I use this mapping in biztalk which can normally process at least 10 messages per second (if not many more :p) but this map is causing a delay, so I can only process 1 message per second :(

Now I am not an xsl guru unfortunatly so if anyone can give me some advice, it is welcome :)

Thx


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)

First, I suggest you can use identity transform with overrides. For example the code below will copy all elements, excluding those "with empty (after whitespace normalization) string values and no child elements or attributes".

<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>

Second, you can try to strip the unused whitespaces in compile-time, by using:

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

This way your document will be kept in memory without insignificant whitespaces and thus will be more concise.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜