Rise_against
Rise_against

Reputation: 1060

xsl reference to external xsl file

I have a question about xsl. I have 1 huge xsl file (+4000 lines :p) and I would like to split the file in different parts. I use the xsl file to map some schemas in BizTalk and it would be more performant if I split it in parts, so I can re-use the parts. Anyway, don't mind the BizTalk stuff, how can I reference from my main xsl file to the different parts?

ex.:

    <?xml version="1.0" encoding="UTF-16"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
      <xsl:template match="/">
        <xsl:apply-templates select="/ns1:ADT_A01_231_GLO_DEF" />
      </xsl:template>
      <xsl:template match="/ns1:ADT_A01_231_GLO_DEF">
        <ns1:ADT_A01_25_GLO_DEF>
          <EVN_EventType>
                <xsl:if test="EVN_EventTypeSegment/EVN_1_EventTypeCode">
                  <EVN_1_EventTypeCode>
                    <xsl:value-of select="EVN_EventTypeSegment/EVN_1_EventTypeCode/text()" />
                  </EVN_1_EventTypeCode>
                </xsl:if>
                <EVN_2_RecordedDateTime>
                  <xsl:if test="EVN_EventTypeSegment/EVN_2_RecordedDateTime/TS_0_TimeOfAnEvent">
                    <TS_0_Time>
                      <xsl:value-of select="EVN_EventTypeSegment/EVN_2_RecordedDateTime/TS_0_TimeOfAnEvent/text()" />
                    </TS_0_Time>
                  </xsl:if>
                  <xsl:if test="EVN_EventTypeSegment/EVN_2_RecordedDateTime/TS_1_DegreeOfPrecision">
                    <TS_1_DegreeOfPrecision>
                      <xsl:value-of select="EVN_EventTypeSegment/EVN_2_RecordedDateTime/TS_1_DegreeOfPrecision/text()" />
                    </TS_1_DegreeOfPrecision>
                  </xsl:if>
                </EVN_2_RecordedDateTime>
          </EVN_EventType>
          <PID_PatientIdentification>
            <xsl:if test="PID_PatientIdentificationSegment/PID_1_SetIdPid">
              <PID_1_SetIdPid>
                <xsl:value-of select="PID_PatientIdentificationSegment/PID_1_SetIdPid/text()" />
              </PID_1_SetIdPid>
            </xsl:if>
           </PID_PatientIdentification>
        </ns1:ADT_A01_25_GLO_DEF>
      </xsl:template>
    </xsl:stylesheet>

So I would like to put the "EVN_EventType" and the "PID_PatientIdentification" in another file. Could be that this xsl isnt 100% valid, I quickly copy/pasted something, but you get my point?

Greatly appreciate any help. Thx

Upvotes: 3

Views: 5478

Answers (3)

Ria Gupta
Ria Gupta

Reputation: 1

You can import an xsl from another xsl by using import statement in the main xsl to use template match from another xsl (say A.xsl). The <xsl:import> element has an href attribute whose value is a URI reference identifying the stylesheet to be imported.

<xsl:import href="A.xsl"/>

Upvotes: 0

LarsH
LarsH

Reputation: 27996

Use <xsl:import> at the top level of the stylesheet, to import templates from other stylesheets. You can:

  • create a named template for EVN_EventType, put it in EVN_EventType.xsl
  • create another named template for PID_PatientIdentification, which you put in PID_PatientIdentification.xsl;
  • then import both stylesheets into your main stylesheet
  • and call both templates from within your <xsl:template match="/ns1:ADT_A01_231_GLO_DEF"> above.

Upvotes: 4

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243459

Read about the <xsl:import> and <xsl:include> instructions. Then use the acquired knowledge.

Upvotes: 2

Related Questions