递归地在不同的 xsl 文件中添加一行行
Posted
技术标签:
【中文标题】递归地在不同的 xsl 文件中添加一行行【英文标题】:Recursively add a block of rows in different xsl files 【发布时间】:2022-01-08 20:35:01 【问题描述】:我有一个主 xsl 文件,我想在其中包含两个 xsl 文件。 我尝试使用 XSL 的包含功能,但没有成功。我在网上阅读了一些示例,但总是出现以下错误: 元素只允许作为样式表的子元素 你能告诉我我做错了什么吗? 在下面我使用的 main.xsl 文件中,我已经在其中插入了 xsl:include: main.xsl:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:include href="distributor.xsl"/>
<mdb:MD_Metadata xmlns:mri="http://standards.iso.org/iso/19115/-3/mri/1.0"
xmlns:mas="http://standards.iso.org/iso/19115/-3/mas/1.0"
xmlns:mrs="http://standards.iso.org/iso/19115/-3/mrs/1.0"
xmlns:mda="http://standards.iso.org/iso/19115/-3/mda/1.0"
xmlns:cit="http://standards.iso.org/iso/19115/-3/cit/2.0"
xmlns:mcc="http://standards.iso.org/iso/19115/-3/mcc/1.0"
xmlns:mdt="http://standards.iso.org/iso/19115/-3/mdt/2.0"
xmlns:msr="http://standards.iso.org/iso/19115/-3/msr/2.0"
xmlns:gex="http://standards.iso.org/iso/19115/-3/gex/1.0"
xmlns:lan="http://standards.iso.org/iso/19115/-3/lan/1.0"
xmlns:gcx="http://standards.iso.org/iso/19115/-3/gcx/1.0"
xmlns:mco="http://standards.iso.org/iso/19115/-3/mco/1.0"
xmlns:mds="http://standards.iso.org/iso/19115/-3/mds/2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gfc="http://standards.iso.org/iso/19110/gfc/1.1"
xmlns:srv="http://standards.iso.org/iso/19115/-3/srv/2.1"
xmlns:mac="http://standards.iso.org/iso/19115/-3/mac/2.0"
xmlns:mdb="http://standards.iso.org/iso/19115/-3/mdb/2.0"
xmlns:mdq="http://standards.iso.org/iso/19157/-2/mdq/1.0"
xmlns:mex="http://standards.iso.org/iso/19115/-3/mex/1.0"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:mrl="http://standards.iso.org/iso/19115/-3/mrl/2.0"
xmlns:mmi="http://standards.iso.org/iso/19115/-3/mmi/1.0"
xmlns:gml="http://www.opengis.net/gml/3.2"
xmlns:mrc="http://standards.iso.org/iso/19115/-3/mrc/2.0"
xmlns:cat="http://standards.iso.org/iso/19115/-3/cat/1.0"
xmlns:mrd="http://standards.iso.org/iso/19115/-3/mrd/1.0"
xmlns:mpc="http://standards.iso.org/iso/19115/-3/mpc/1.0"
xmlns:gmd="http://www.isotc211.org/2005/gmd"
xmlns:gco="http://standards.iso.org/iso/19115/-3/gco/1.0"
xmlns:old="http://www.isotc211.org/2005/gco"
xmlns:old_gml="http://www.opengis.net/gml">
<!-- DEFINE global variable here -->
<xsl:variable name="geonetwork_server" select="'http://myserver'" />
<xsl:variable name="webgis_geoserver" select="'http://webgis/geoserver/'" />
<xsl:variable name="openeo_collections" select="'https://mycollections/'" />
<xsl:variable name="collection_thumb_folder" select="'https://thumb_collections/'" />
<!-- ************************** -->
<mdb:metadataIdentifier>
<mcc:MD_Identifier>
<mcc:code>
<gco:CharacterString>$UUID</gco:CharacterString>
</mcc:code>
<mcc:codeSpace>
<gco:CharacterString>urn:uuid</gco:CharacterString>
</mcc:codeSpace>
</mcc:MD_Identifier>
</mdb:metadataIdentifier>
<mdb:defaultLocale>
<lan:PT_Locale id="EN">
<lan:language>
<lan:LanguageCode codeList="http://www.loc.gov/standards/iso639-2/" codeListValue="eng"/>
</lan:language>
<lan:characterEncoding>
<lan:MD_CharacterSetCode codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/ML_gmxCodelists.xml#MD_CharacterSetCode"
codeListValue="utf8"/>
</lan:characterEncoding>
</lan:PT_Locale>
</mdb:defaultLocale>
<mdb:metadataScope>
<mdb:MD_MetadataScope>
<mdb:resourceScope>
<mcc:MD_ScopeCode codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/ML_gmxCodelists.xml#MD_ScopeCode"
codeListValue="dataset"/>
</mdb:resourceScope>
</mdb:MD_MetadataScope>
</mdb:metadataScope>
<mdb:contact>
<cit:CI_Responsibility>
<cit:role>
<cit:CI_RoleCode codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/ML_gmxCodelists.xml#CI_RoleCode"
codeListValue="pointOfContact"/>
</cit:role>
<cit:party>
<cit:CI_Organisation>
<cit:name>
<gco:CharacterString>Institute </gco:CharacterString>
</cit:name>
<cit:contactInfo>
<cit:CI_Contact>
<cit:address>
<cit:CI_Address>
<cit:deliveryPoint>
<gco:CharacterString>address</gco:CharacterString>
</cit:deliveryPoint>
<cit:city>
<gco:CharacterString>city</gco:CharacterString>
</cit:city>
<cit:administrativeArea>
<gco:CharacterString>area</gco:CharacterString>
</cit:administrativeArea>
<cit:postalCode>
<gco:CharacterString>CAP</gco:CharacterString>
</cit:postalCode>
<cit:country>
<gco:CharacterString>nation</gco:CharacterString>
</cit:country>
<cit:electronicMailAddress>
<gco:CharacterString>email@gmail.com</gco:CharacterString>
</cit:electronicMailAddress>
</cit:CI_Address>
</cit:address>
<cit:onlineResource>
<cit:CI_OnlineResource>
<cit:linkage>
<gco:CharacterString>http://my_website</gco:CharacterString>
</cit:linkage>
<cit:protocol>
<gco:CharacterString>WWW:LINK-1.0-http--link</gco:CharacterString>
</cit:protocol>
<cit:applicationProfile>
<gco:CharacterString>profile</gco:CharacterString>
</cit:applicationProfile>
<cit:name>
<gco:CharacterString>name</gco:CharacterString>
</cit:name>
<cit:function>
<cit:CI_OnLineFunctionCode codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/ML_gmxCodelists.xml#CI_OnLineFunctionCode"
codeListValue="information"/>
</cit:function>
</cit:CI_OnlineResource>
</cit:onlineResource>
</cit:CI_Contact>
</cit:contactInfo>
<cit:individual>
<cit:CI_Individual>
<cit:name>
<gco:CharacterString>Bruce Banner</gco:CharacterString>
</cit:name>
<cit:positionName>
<gco:CharacterString>Researcher</gco:CharacterString>
</cit:positionName>
</cit:CI_Individual>
</cit:individual>
</cit:CI_Organisation>
</cit:party>
</cit:CI_Responsibility>
</mdb:contact>
<mdb:dateInfo>
<cit:CI_Date>
<cit:date>
<gco:DateTime>$DATE_REVISION</gco:DateTime>
</cit:date>
<cit:dateType>
<cit:CI_DateTypeCode codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/ML_gmxCodelists.xml#CI_DateTypeCode"
codeListValue="revision"/>
</cit:dateType>
</cit:CI_Date>
</mdb:dateInfo>
<mdb:dateInfo>
<cit:CI_Date>
<cit:date>
<gco:DateTime><xsl:value-of select="/STAC/metadata/creation_time" /></gco:DateTime>
</cit:date>
<cit:dateType>
<cit:CI_DateTypeCode codeList="https://standards.iso.org/iso/19115/resources/Codelists/cat/codelists.xml#CI_DateTypeCode"
codeListValue="creation">creation</cit:CI_DateTypeCode>
</cit:dateType>
</cit:CI_Date>
</mdb:dateInfo>
<mdb:metadataStandard>
<cit:CI_Citation>
<cit:title>
<gco:CharacterString>ISO 19115-3</gco:CharacterString>
</cit:title>
</cit:CI_Citation>
</mdb:metadataStandard>
<mdb:metadataLinkage>
<cit:CI_OnlineResource>
<cit:linkage>
<gco:CharacterString><xsl:value-of select="$geonetwork_server" />$UUID</gco:CharacterString>
</cit:linkage>
<cit:function>
<cit:CI_OnLineFunctionCode codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/ML_gmxCodelists.xml#CI_OnLineFunctionCode"
codeListValue="completeMetadata"/>
</cit:function>
</cit:CI_OnlineResource>
</mdb:metadataLinkage>
<mdb:spatialRepresentationInfo>
<msr:MD_GridSpatialRepresentation>
<msr:numberOfDimensions>
<gco:Integer>2</gco:Integer>
</msr:numberOfDimensions>
<msr:axisDimensionProperties>
<msr:MD_Dimension>
<msr:dimensionName>
<msr:MD_DimensionNameTypeCode codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/ML_gmxCodelists.xml#MD_DimensionNameTypeCode"
codeListValue="row"/>
</msr:dimensionName>
<msr:dimensionSize>
<gco:Integer><xsl:value-of select="/STAC/metadata/properties/dimensions/rows" /></gco:Integer>
</msr:dimensionSize>
<msr:resolution>
<gco:Distance uom="m"><xsl:value-of select="/STAC/metadata/properties/bands/band[@bandId=1]/gsd" /></gco:Distance>
</msr:resolution>
<msr:dimensionTitle gco:nilReason="missing">
<gco:CharacterString/>
</msr:dimensionTitle>
<msr:dimensionDescription>
<gco:CharacterString>dims description </gco:CharacterString>
</msr:dimensionDescription>
</msr:MD_Dimension>
</msr:axisDimensionProperties>
<msr:axisDimensionProperties>
<msr:MD_Dimension>
<msr:dimensionName>
<msr:MD_DimensionNameTypeCode codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/ML_gmxCodelists.xml#MD_DimensionNameTypeCode"
codeListValue="column"/>
</msr:dimensionName>
<msr:dimensionSize>
<gco:Integer><xsl:value-of select="/STAC/metadata/properties/dimensions/columns" /></gco:Integer>
</msr:dimensionSize>
<msr:resolution>
<gco:Length uom="m"><xsl:value-of select="/STAC/metadata/properties/bands/band[@bandId=1]/gsd" /></gco:Length>
</msr:resolution>
<msr:dimensionTitle gco:nilReason="missing">
<gco:CharacterString/>
</msr:dimensionTitle>
<msr:dimensionDescription>
<gco:CharacterString>dims description </gco:CharacterString>
</msr:dimensionDescription>
</msr:MD_Dimension>
</msr:axisDimensionProperties>
<msr:cellGeometry>
<msr:MD_CellGeometryCode codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/ML_gmxCodelists.xml#MD_CellGeometryCode"
codeListValue="area"/>
</msr:cellGeometry>
<msr:transformationParameterAvailability>
<gco:Boolean>false</gco:Boolean>
</msr:transformationParameterAvailability>
</msr:MD_GridSpatialRepresentation>
</mdb:spatialRepresentationInfo>
<mdb:referenceSystemInfo>
<mrs:MD_ReferenceSystem>
<mrs:referenceSystemIdentifier>
<mcc:MD_Identifier>
<mcc:code>
<gco:CharacterString><xsl:value-of select="/STAC/metadata/extent/spatial/epsg" /></gco:CharacterString>
</mcc:code>
<mcc:codeSpace>
<gco:CharacterString>EPSG</gco:CharacterString>
</mcc:codeSpace>
<mcc:description>
<gco:CharacterString>WGS-84</gco:CharacterString>
</mcc:description>
</mcc:MD_Identifier>
</mrs:referenceSystemIdentifier>
<mrs:referenceSystemType>
<mrs:MD_ReferenceSystemTypeCode codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/ML_gmxCodelists.xml#MD_ReferenceSystemTypeCode"
codeListValue="projected"/>
</mrs:referenceSystemType>
</mrs:MD_ReferenceSystem>
</mdb:referenceSystemInfo>
<mdb:identificationInfo>
<mri:MD_DataIdentification>
<mri:citation>
<cit:CI_Citation>
<cit:title>
<gco:CharacterString><xsl:value-of select="/STAC/metadata/title" /></gco:CharacterString>
</cit:title>
<cit:alternateTitle>
<gco:CharacterString><xsl:value-of select="/STAC/metadata/id" /></gco:CharacterString>
</cit:alternateTitle>
<cit:date>
<cit:CI_Date>
<cit:date>
<gco:DateTime>
<xsl:value-of select="/STAC/metadata/creation_time" />
</gco:DateTime>
</cit:date>
<cit:dateType>
<cit:CI_DateTypeCode codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/ML_gmxCodelists.xml#CI_DateTypeCode"
codeListValue="creation"/>
</cit:dateType>
</cit:CI_Date>
</cit:date>
<!-- TEST INCLUDE -->
<!-- <xsl:include href = "publication_date.xsl"/>-->
<!-- TEST INCLUDE -->
<cit:edition>
<gco:CharacterString>INSERT HERE THE CURRENT VERSION OF THE CITED RESOURCE</gco:CharacterString>
</cit:edition>
<cit:identifier>
<mcc:MD_Identifier>
<mcc:code>
<gco:CharacterString>publisher</gco:CharacterString>
</mcc:code>
<mcc:codeSpace>
<xsl:variable name="my_collection_id" select="/STAC/metadata/id"/>
<gco:CharacterString><xsl:value-of select="concat($openeo_collections,$my_collection_id)"/></gco:CharacterString>
</mcc:codeSpace>
</mcc:MD_Identifier>
</cit:identifier>
<cit:presentationForm>
<cit:CI_PresentationFormCode codeListValue="mapDigital"
codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/ML_gmxCodelists.xml#CI_PresentationFormCode"/>
</cit:presentationForm>
</cit:CI_Citation>
</mri:citation>
<mri:abstract>
<gco:CharacterString><xsl:value-of select="/STAC/metadata/description" /></gco:CharacterString>
</mri:abstract>
<mri:purpose>
<gco:CharacterString><xsl:value-of select="/STAC/metadata/citation" /></gco:CharacterString>
</mri:purpose>
<mri:status>
<mcc:MD_ProgressCode codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/ML_gmxCodelists.xml#MD_ProgressCode"
codeListValue="onGoing"/>
</mri:status>
<mri:pointOfContact>
<cit:CI_Responsibility>
<cit:role>
<cit:CI_RoleCode codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/ML_gmxCodelists.xml#CI_RoleCode"
codeListValue="custodian"/>
</cit:role>
<cit:party>
<cit:CI_Organisation>
<cit:name>
<gco:CharacterString>Organisation</gco:CharacterString>
</cit:name>
<cit:contactInfo>
<cit:CI_Contact>
<cit:address>
<cit:CI_Address>
<cit:deliveryPoint>
<gco:CharacterString>address</gco:CharacterString>
</cit:deliveryPoint>
<cit:city>
<gco:CharacterString>city</gco:CharacterString>
</cit:city>
<cit:administrativeArea>
<gco:CharacterString>Area</gco:CharacterString>
</cit:administrativeArea>
<cit:postalCode>
<gco:CharacterString>Postal_code</gco:CharacterString>
</cit:postalCode>
<cit:country>
<gco:CharacterString>nation</gco:CharacterString>
</cit:country>
<cit:electronicMailAddress>
<gco:CharacterString>email</gco:CharacterString>
</cit:electronicMailAddress>
</cit:CI_Address>
</cit:address>
<cit:onlineResource>
<cit:CI_OnlineResource>
<cit:linkage>
<gco:CharacterString>http://www.my_web.it</gco:CharacterString>
</cit:linkage>
<cit:protocol>
<gco:CharacterString>WWW:LINK-1.0-http--link</gco:CharacterString>
</cit:protocol>
<cit:name>
<gco:CharacterString>eurac research</gco:CharacterString>
</cit:name>
<cit:function>
<cit:CI_OnLineFunctionCode codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/ML_gmxCodelists.xml#CI_OnLineFunctionCode"
codeListValue="information"/>
</cit:function>
</cit:CI_OnlineResource>
</cit:onlineResource>
</cit:CI_Contact>
</cit:contactInfo>
<cit:logo>
<mcc:MD_BrowseGraphic>
<mcc:fileName>
<gco:CharacterString>logo.jpg</gco:CharacterString>
</mcc:fileName>
<mcc:fileDescription>
<gco:CharacterString>Project logo</gco:CharacterString>
</mcc:fileDescription>
<mcc:fileType>
<gco:CharacterString>JPEG</gco:CharacterString>
</mcc:fileType>
</mcc:MD_BrowseGraphic>
</cit:logo>
<xsl:for-each select="/STAC/metadata/properties/responsibles/responsible">
<cit:individual>
<cit:CI_Individual>
<cit:name>
<gco:CharacterString> <xsl:value-of select="."/></gco:CharacterString>
</cit:name>
<cit:positionName>
<gco:CharacterString><xsl:value-of select="@value" /></gco:CharacterString>
</cit:positionName>
</cit:CI_Individual>
</cit:individual>
</xsl:for-each>
</cit:CI_Organisation>
</cit:party>
</cit:CI_Responsibility>
</mri:pointOfContact>
<mri:spatialRepresentationType>
<mcc:MD_SpatialRepresentationTypeCode codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/ML_gmxCodelists.xml#MD_SpatialRepresentationTypeCode"
codeListValue="grid"/>
</mri:spatialRepresentationType>
<!-- <mri:topicCategory>
<mri:MD_TopicCategoryCode>Land</mri:MD_TopicCategoryCode>
</mri:topicCategory>-->
</mri:MD_DataIdentification>
</mdb:identificationInfo>
<mdb:distributionInfo>
<mrd:MD_Distribution>
<mrd:distributionFormat>
<mrd:MD_Format>
<mrd:formatSpecificationCitation>
<cit:CI_Citation>
<cit:title>
<gco:CharacterString>WCS</gco:CharacterString>
</cit:title>
<cit:date gco:nilReason="unknown"/>
<cit:edition>
<gco:CharacterString>2.0</gco:CharacterString>
</cit:edition>
</cit:CI_Citation>
</mrd:formatSpecificationCitation>
</mrd:MD_Format>
</mrd:distributionFormat>
<!-- TEST INCLUDE -->
<!-- <xsl:include href = "distributor.xsl"/> -->
<xsl:call-template name="distributor.xsl"/>
<!-- TEST INCLUDE -->
<mrd:transferOptions>
<mrd:MD_DigitalTransferOptions>
<mrd:onLine>
<cit:CI_OnlineResource>
<cit:linkage>
<gco:CharacterString>https://my_collections/</gco:CharacterString>
</cit:linkage>
<cit:protocol>
<gco:CharacterString>OGC:WCS</gco:CharacterString>
</cit:protocol>
<cit:name>
<gco:CharacterString><xsl:value-of select="/STAC/metadata/id" /></gco:CharacterString>
</cit:name>
<cit:description>
<gco:CharacterString>DESCRIBE HERE THE RESOURCE</gco:CharacterString>
</cit:description>
<cit:function>
<cit:CI_OnLineFunctionCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_OnLineFunctionCode"
codeListValue="fileAccess"/>
</cit:function>
</cit:CI_OnlineResource>
</mrd:onLine>
</mrd:MD_DigitalTransferOptions>
</mrd:transferOptions>
</mrd:MD_Distribution>
</mdb:distributionInfo>
</mdb:MD_Metadata>
</xsl:template>
</xsl:stylesheet>
这些是要包含的两个 xsl:publication_date.xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<!-- HERE the same namespace as in main.xsl -->
<cit:date>
<cit:CI_Date>
<cit:date>
<gco:Date><xsl:value-of select="/STAC/metadata/creation_time" /></gco:Date>
</cit:date>
<cit:dateType>
<cit:CI_DateTypeCode codeList="http://standards.iso.org/iso/19115/resources/Codelists/cat/codelists.xml#CI_DateTypeCode" codeListValue="publication"/>
</cit:dateType>
</cit:CI_Date>
</cit:date>
</xsl:template>
</xsl:stylesheet>
distributor.xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- <xsl:template match="/">-->
<xsl:template name="DOI_publisher.xsl">
<!-- HERE the same namespace as in main.xsl -->
<mrd:distributor>
<mrd:MD_Distributor>
<mrd:distributorContact>
<cit:CI_Responsibility>
<cit:role>
<cit:CI_RoleCode codeList="http://standards.iso.org/iso/19115/resources/Codelists/cat/codelists.xml#CI_RoleCode"
codeListValue="publisher"/>
</cit:role>
<cit:party>
<cit:CI_Organisation>
<cit:name>
<gco:CharacterString>institute2</gco:CharacterString>
</cit:name>
<cit:contactInfo>
<cit:CI_Contact>
<cit:address>
<cit:CI_Address>
<cit:deliveryPoint>
<gco:CharacterString>address2</gco:CharacterString>
</cit:deliveryPoint>
<cit:city>
<gco:CharacterString>city2</gco:CharacterString>
</cit:city>
<cit:administrativeArea>
<gco:CharacterString>area2</gco:CharacterString>
</cit:administrativeArea>
<cit:postalCode>
<gco:CharacterString>Postal_code2</gco:CharacterString>
</cit:postalCode>
<cit:country>
<gco:CharacterString>Nation2</gco:CharacterString>
</cit:country>
<cit:electronicMailAddress>
<gco:CharacterString>email2</gco:CharacterString>
</cit:electronicMailAddress>
</cit:CI_Address>
</cit:address>
</cit:CI_Contact>
</cit:contactInfo>
</cit:CI_Organisation>
</cit:party>
</cit:CI_Responsibility>
</mrd:distributorContact>
</mrd:MD_Distributor>
</mrd:distributor>
</mdb:MD_Metadata>
</xsl:template>
</xsl:stylesheet>
【问题讨论】:
不完全重复,但密切相关:xpath for Python,尤其是 Gringo Suave 的回答。 XSLT 可以通过 XSLT 处理来实现,您可以从 Python 运行 XSLT。 【参考方案1】:为什么不使用 XSLT 呢?
注意,如果您有一系列类似的 XSLT 文件,并且需要对每个文件进行类似的更改,那么这是一个强烈的信号,表明是时候进行一些重构以提高代码的重用性了。最简单的方法是将公共代码提取到您使用xsl:include
合并的共享模块中。还有其他更复杂的方法,例如从通用母版生成 XSLT 样式表。 XSLT 是 XML 的事实使得使用 XSLT 操作 XSLT 成为一种非常可行的技术。
稍后
好的,您接受了我的建议,并修改了您的问题以显示您到达的位置和遇到的问题。这实际上不是一个很好的推进 SO 的方法:如果你继续编辑问题而我继续编辑答案,那么以后来这里的任何人都会发现很难理解。下一次,提出一个新问题。
您误解了xsl:include
的工作原理。在您编写xsl:include
的地方,将其替换为<xsl:call-template name="some.code"/>
。将xsl:include
声明放在main.xsl
样式表的顶层(作为xsl:stylesheet
的子级),并在包含的模块中包含一个命名模板<xsl:template name="some.code">....</xsl:template>
。
【讨论】:
感谢您的建议。如您所见,我在这里添加了我尝试使用但没有成功的文件。你能解释一下我的文件有什么问题吗? 我很抱歉我的不良行为,但我认为它可以更好地理解我的问题。我会牢记这一点,以备将来之用。顺便说一句,我仍然无法真正理解xsl:include
的用法。我遵循您的建议,但是当我运行xsltproc
时出现此错误:xsltproc -o include_test.xml main.xsl ADO_EU_DEM_25m_3035.xml
runtime error: file main.xsl line 442 element call-template 未找到被调用的模板'distributor.xsl'。错误:文件 ADO_EU_DEM_25m_3035.xml xsltRunStylesheet:运行失败
我想我找到了问题所在。我忘了在distributor.xsl 文件中插入.xsl 现在它是<xsl:template name="distributor.xsl">
并且已经添加了相应的部分:)以上是关于递归地在不同的 xsl 文件中添加一行行的主要内容,如果未能解决你的问题,请参考以下文章
递归地在任何jsphpinchtmhtmlcss文件中查找字符串