Copy xml document's images in different source locations into single output directory

馋奶兔 提交于 2019-12-01 09:35:55

This is not a complete solution but it may be enough for your needs. The following XSLT 2.0 style-sheet copies a document, expanding out XIncludes (with caveats noted following).

<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xi="http://www.w3.org/2001/XInclude"
  xmlns:fn="http://www.w3.org/2005/xpath-functions"
  exclude-result-prefixes='xsl xi fn'>
<xsl:output method="xml" indent="yes"/>

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

<xsl:template match="xi:include[@href][@parse='xml' or not(@parse)][fn:unparsed-text-available(@href)]">
 <xsl:apply-templates select="fn:document(@href)" />
</xsl:template>

<xsl:template match="xi:include[@href][@parse='text'][fn:unparsed-text-available(@href)]">
 <xsl:apply-templates select="fn:unparsed-text(@href,@encoding)" />
</xsl:template>

<xsl:template match="xi:include[@href][@parse=('text','xml') or not(@parse)][not(fn:unparsed-text-available(@href))][xi:fallback]">
 <xsl:apply-templates select="xi:fallback/text()" />
</xsl:template>

<xsl:template match="xi:include" />

</xsl:stylesheet> 

Caveats

This solution does not implement the attributes: xpointer, accept and accept-language.

Crippled XSLT 1.0 variant

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xi="http://www.w3.org/2001/XInclude"
  exclude-result-prefixes='xsl xi'>
<xsl:output method="xml" indent="yes"/>

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

<xsl:template match="xi:include[@href][@parse='xml' or not(@parse)]">
 <xsl:apply-templates select="document(@href)" />
</xsl:template>

<xsl:template match="xi:include" />

</xsl:stylesheet> 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!