我有一个xml文档,使用xinclude访问其他几个xml文件.
<chapter xml:id="chapter1">
<title>Chapter in Main Doc</title>
<section xml:id="section">
<title>Section in Main Doc 1</title>
<mediaobject>
<imageobject>
<imagedata fileref="images/car.jpg"/>
</imageobject>
</mediaobject>
</section>
<xi:include href="../some-doc/section1.xml"/>
<xi:include href="../some-doc/section2.xml"/>
Run Code Online (Sandbox Code Playgroud)
这些其他section1和section2 xml文件在不同的源位置使用不同的图像.我需要将所有图像复制到单个输出目录.首先,我计划使用XSLT来解析整个xml文档并生成要复制的图像列表.如何使用XSLT生成xml文件的图像列表?你的想法真的很感激.
提前致谢..!!
添加:
我尝试了下面回答的XSLT 1.0代码.当我使用它生成html输出时,它只显示章节和节id,如"chapter1,section ...".它不显示imagedata节点内的图像路径值.
但是,当我改变<xsl:template match="@*|node()">作为<xsl:template match="*">然后显示的xincluded XML文件也全部图像路径值.但是还有其他节点的值也如上所述.我需要过滤除图像路径以外的所有值.
在这里,我只需要复制所有xml文档的图像路径,并将所有路径保存在数组或类似的东西中.然后我可以使用这些保存的图像路径来使用java类进行图像处理.
这不是一个完整的解决方案,但它可能足以满足您的需求.以下XSLT 2.0样式表复制文档,扩展XIncludes(注意下面的注意事项).
<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>
Run Code Online (Sandbox Code Playgroud)
此解决方案不实现属性:xpointer,accept和accept-language.
<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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1664 次 |
| 最近记录: |