0

他のxmlファイルをxincludeするxmlドキュメントがあります。これらの xml ファイルにはすべて、異なるソースの場所にある画像の相対パスが含まれています。

<chapter xml:id="chapter1">
    <title>First chapter in Main Document</title>
    <section xml:id="section1">
        <title>Section 1 in Main Document</title>
        <para>this is paragraph<figure>
                <title>Car images</title>
                <mediaobject>
                    <imageobject>
                        <imagedata fileref="images/image1.jpg"/>
                    </imageobject>
                </mediaobject>
            </figure></para>
    </section>
    <xi:include href="../doc/section2.xml"/>
    <xi:include href="../doc/section3.xml"/>
</chapter>

section2 と section3 の xml ドキュメントは次のようになります。

<section xml:id="section2"  
        <title>Main Documentation Section2</title>
        <para>This is also paragraph <figure>
                <title>Different Images</title>
                <mediaobject>
                    <imageobject>
                        <imagedata fileref="images/image2.jpg"/>
                    </imageobject>
                </mediaobject>
            </figure></para>
    </section>

すべての xml ドキュメントで画像パスのリストを生成する XSLT 1.0 スタイル シートを作成したいと考えています。異なるソースの場所にあるこれらの画像を単一の画像フォルダーにコピーします。次に、そのイメージ パスのリストを使用して、それらのイメージをコピーできます。そして、その画像パスリストがJavaクラスでアクセスできる構造に保存されていれば素晴らしいでしょう。

現在、別の質問から得た XSLT を使用しています。しかし、この XSLT は、他のノードの値をイメージ パスと共に提供します。テンプレートの値を変更して、たくさんフィルターをかけてみました。

<xsl:template match="*">
<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>

期待される結果リストは、次のようなものになります。

/home/vish/test/images/image1.jpg

/home/vish/test/doc/other/images/image2.jpg

/home/vish/test2/other/images/image3.jpg

前もって感謝します..!!

4

1 に答える 1

2

どうですか...

<?xml version="1.0" encoding="utf-8"?>
<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:strip-space elements="*" />

<xsl:template match="/">
 <image-paths>
  <xsl:apply-templates select="*" />
 </image-paths>
</xsl:template>

<xsl:template match="*">
 <xsl:apply-templates select="*" />
</xsl:template>

<xsl:template match="imagedata">
 <imagedata fileref="{@fileref}" />
</xsl:template>

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

</xsl:stylesheet>

次のような出力が得られるはずです...

<image-paths>
 <imagedata fileref="path1/image1.jpg" />
 <imagedata fileref="path2/image2.jpg" />
 <imagedata fileref="path3/image3.jpg" />
</image-paths>
于 2012-07-16T16:29:34.747 に答える