xsl 对外部 xsl 文件的引用
我有一个关于 xsl 的问题。我有 1 个巨大的 xsl 文件(+4000 行:p),我想将该文件拆分为不同的部分。我使用 xsl 文件来映射 BizTalk 中的一些架构,如果我将其分成几部分,性能会更高,这样我就可以重复使用这些部分。无论如何,不要介意 BizTalk 的东西,我如何从我的主 xsl 文件引用不同的部分?
例如:
<?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>
所以我想将“EVN_EventType”和“PID_PatientIdentification”放在另一个文件中。 可能这个 xsl 不是 100% 有效,我快速复制/粘贴了一些内容,但你明白我的意思吗?
非常感谢任何帮助。 谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
在样式表的顶层,从其他样式表导入模板。您可以:EVN_EventType,放入
EVN_EventType.xsl
命名模板为
PID_PatientIdentification,您可以
放入 PID_PatientIdentification.xsl;
在上面的
中。Use
<xsl:import>
at the top level of the stylesheet, to import templates from other stylesheets. You can:EVN_EventType, put it in
EVN_EventType.xsl
named template for
PID_PatientIdentification, which you
put in PID_PatientIdentification.xsl;
within your
<xsl:template match="/ns1:ADT_A01_231_GLO_DEF">
above.了解
和< /code>
说明
。然后运用所学到的知识。
Read about the
<xsl:import>
and<xsl:include>
instructions. Then use the acquired knowledge.您可以通过在主 xsl 中使用 import 语句从另一个 xsl 导入 xsl,以使用另一个 xsl 中的模板匹配(例如 A.xsl)。
元素有一个 href 属性,其值是标识要导入的样式表的 URI 引用。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.