0

xml ドキュメントからさまざまな名前空間を取得して、xsl-fo への変換に使用する方法を知りたいです。私が持っているものは次のとおりです。

XML:

<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="style.xsl" ?>
<ovgs xmlns:ncb="http://www.namcobandai.com/NS" xmlns:sqe="http://www.squareenix.com/NS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="main.xsd">
<upcoming>
<ncb:game>
    <ncb:cover>nnk_cover.jpg</ncb:cover>
    <ncb:title>Ni no Kuni: Wrath of the White Witch</ncb:title>
    <ncb:publisher>Namco Bandai Games America</ncb:publisher>
    <ncb:developer>Level 5</ncb:developer>
    <ncb:genre>Role-Playing</ncb:genre>
    <ncb:releaseDate>
        <ncb:yyyy>2013</ncb:yyyy>
        <ncb:mm>01</ncb:mm>
        <ncb:dd>22</ncb:dd>
    </ncb:releaseDate>
    <ncb:esrbRating>E10+</ncb:esrbRating>
    <ncb:platforms>
        <ncb:platform>PS3</ncb:platform>
    </ncb:platforms>
</ncb:game>
<sqe:game>
    <sqe:cover>tr_cover.jpg</sqe:cover>
    <sqe:title>Tomb Raider</sqe:title>
    <sqe:publisher>Square Enix</sqe:publisher>
    <sqe:developer>Crystal Dynamics</sqe:developer>
    <sqe:genre>Action</sqe:genre>
    <sqe:releaseDate>
        <sqe:yyyy>2013</sqe:yyyy>
        <sqe:mm>03</sqe:mm>
        <sqe:dd>05</sqe:dd>
    </sqe:releaseDate>
    <sqe:esrbRating>M</sqe:esrbRating>
    <sqe:platforms>
        <sqe:platform>X360</sqe:platform>
        <sqe:platform>PC</sqe:platform>
        <sqe:platform>PS3</sqe:platform>
    </sqe:platforms>
</sqe:game>
<sqe:game>
    <sqe:cover>hma_cover.jpg</sqe:cover>
    <sqe:title>Hitman: Absolution</sqe:title>
    <sqe:publisher>Square Enix</sqe:publisher>
    <sqe:developer>Io Interactive</sqe:developer>
    <sqe:genre>Action</sqe:genre>
    <sqe:releaseDate>
        <sqe:yyyy>2012</sqe:yyyy>
        <sqe:mm>11</sqe:mm>
        <sqe:dd>20</sqe:dd>
    </sqe:releaseDate>
    <sqe:esrbRating>M</sqe:esrbRating>
    <sqe:platforms>
        <sqe:platform>X360</sqe:platform>
        <sqe:platform>PC</sqe:platform>
        <sqe:platform>PS3</sqe:platform>
    </sqe:platforms>
</sqe:game>
</upcoming>

私が欲しいのは、その情報を取得して xsl-fo ドキュメントに変換する xslt ファイルのコードです。そして、基本的に私が苦労しているのは、ノードを参照する方法だけです。私がこれまでに持っているもの:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
    <fo:root>
        <!-- overall layout -->
        <fo:layout-master-set>
            <fo:simple-page-master master-name="coverPage">
                <fo:region-body/>
                <fo:region-before   extent="1in" />
                <fo:region-after    extent="1in" />
                <fo:region-start    extent="1in" />
                <fo:region-end  extent="1in" />
            </fo:simple-page-master>

            <fo:simple-page-master master-name="contentPage">
                <fo:region-body/>
                <fo:region-before   extent="1in" background-color="#0000FF" />
                <fo:region-after    extent="1in" background-color="#0000FF" />
                <fo:region-start/>
                <fo:region-end/>
            </fo:simple-page-master>
        </fo:layout-master-set>
        <!-- page content -->
        <fo:page-sequence master-reference="coverPage">
            <fo:flow flow-name="xsl-region-body">
                <fo:block margin-top="2.5in" text-align="center"><fo:external-graphic content-height="scale-to-fit" height="2.5in" src="ovgsLogo.jpg" /></fo:block>
                <fo:block font-weight="bold" text-align="center">Greetings all yee gamers!</fo:block>
            </fo:flow>
        </fo:page-sequence>

        <xsl:for-each select="../upcoming/ncb:game">
            <fo:page-sequence master-reference="contentPage">
                <fo:static-content flow-name="xsl-region-before">
                    <fo:block margin-top="0.3in" text-align="center">OVGS Upcoming Games</fo:block>
                </fo:static-content>

                <fo:static-content flow-name="xsl-region-after">
                    <fo:block margin-top="0.3in" text-align="center">Page <fo:page-number /></fo:block>
                </fo:static-content>

                <fo:flow flow-name="xsl-region-body">
                    <fo:block font-size="24pt" font-weight="bold" text-align="center" margin-top="2.5in" color="#FF0000"><xsl:value-of select="ncb:title" /></fo:block>
                    <fo:block text-align="center" margin-top="0.2in"><fo:external-graphic content-height="scale-to-fit" height="3in"><xsl:attribute name="src">url('<xsl:value-of select="ncb:cover" />')</xsl:attribute></fo:external-graphic></fo:block>
                    <fo:block font-weight="bold" text-align="center" margin-top="0.3in">Published by <xsl:value-of select="ncb:publisher" /></fo:block>
                    <fo:block font-weight="bold" text-align="center">Developed by <xsl:value-of select="ncb:developer" /></fo:block>
                    <fo:block font-weight="bold" text-align="center"><xsl:value-of select="ncb:genre" /></fo:block>
                    <fo:block font-weight="bold" text-align="center">Released on <xsl:value-of select="ncb:releaseDate/ncb:dd" />/<xsl:value-of select="ncb:releaseDate/ncb:mm" />/<xsl:value-of select="ncb:releaseDate/ncb:yyyy" /></fo:block>
                    <fo:block font-weight="bold" text-align="center">
                        Available on <xsl:value-of select="ncb:platforms/ncb:platform[1]" /><xsl:for-each select="ncb:platforms/ncb:platform">
                        <xsl:if test="position() != last() and position() != 1">, <xsl:value-of select="." /></xsl:if></xsl:for-each> and <xsl:value-of select="ncb:platforms/ncb:platform[last()]" />
                    </fo:block>
                    <fo:block text-align="center" background-color="#9900FF" margin-top="0.3in" margin-left="1in" margin-right="1in"><xsl:value-of select="ncb:esrbRating" /></fo:block>
                </fo:flow>
            </fo:page-sequence>
        </xsl:for-each>

        <xsl:for-each select="ovgs/upcoming/sqe:game">
            <fo:page-sequence master-reference="contentPage">
                <fo:static-content flow-name="xsl-region-before">
                    <fo:block margin-top="0.3in" text-align="center">OVGS Upcoming Games</fo:block>
                </fo:static-content>

                <fo:static-content flow-name="xsl-region-after">
                    <fo:block margin-top="0.3in" text-align="center">Page <fo:page-number /></fo:block>
                </fo:static-content>

                <fo:flow flow-name="xsl-region-body">
                    <fo:block font-size="24pt" font-weight="bold" text-align="center" margin-top="2.5in" color="#FF0000"><xsl:value-of select="sqe:title" /></fo:block>
                    <fo:block text-align="center" margin-top="0.2in"><fo:external-graphic content-height="scale-to-fit" height="3in"><xsl:attribute name="src">url('<xsl:value-of select="sqe:cover" />')</xsl:attribute></fo:external-graphic></fo:block>
                    <fo:block font-weight="bold" text-align="center" margin-top="0.3in">Published by <xsl:value-of select="sqe:publisher" /></fo:block>
                    <fo:block font-weight="bold" text-align="center">Developed by <xsl:value-of select="sqe:developer" /></fo:block>
                    <fo:block font-weight="bold" text-align="center"><xsl:value-of select="sqe:genre" /></fo:block>
                    <fo:block font-weight="bold" text-align="center">Released on <xsl:value-of select="sqe:releaseDate/sqe:dd" />/<xsl:value-of select="sqe:releaseDate/sqe:mm" />/<xsl:value-of select="sqe:releaseDate/sqe:yyyy" /></fo:block>
                    <fo:block font-weight="bold" text-align="center">
                        Available on <xsl:value-of select="sqe:platforms/sqe:platform[1]" /><xsl:for-each select="sqe:platforms/sqe:platform">
                        <xsl:if test="position() != last() and position() != 1">, <xsl:value-of select="." /></xsl:if></xsl:for-each> and <xsl:value-of select="sqe:platforms/sqe:platform[last()]" />
                    </fo:block>
                    <fo:block text-align="center" background-color="#9900FF" margin-top="0.3in" margin-left="1in" margin-right="1in"><xsl:value-of select="sqe:esrbRating" /></fo:block>
                </fo:flow>
            </fo:page-sequence>
        </xsl:for-each>

    </fo:root>
</xsl:template>

4

2 に答える 2

1

以下のコーディングを使用してタイトルを取得します

//*[local-name(.)='game'][1]/*[local-name(.)='title']

また、以下のコーディングに従って入力 XML を変更します。

<?xml version="1.0"?>
<test xmlns:ubisoft="http://www.mytext.com" xmlns:atari="http://www.yourtext.com">
<ubisoft:game>
    <ubisoft:title>Assassin's creed</ubisoft:title>
    <ubisoft:rating/>
    <!--etc-->
</ubisoft:game>
<ubisoft:game>
    <ubisoft:title>Far Cry 3</ubisoft:title>
    <ubisoft:rating/>
    <!--etc-->
</ubisoft:game>
<atari:game>
    <atari:title/>
    <atari:rating/>
    <!--etc-->
</atari:game>
<atari:game>
    <atari:title/>
    <atari:rating/>
    <!--etc-->
</atari:game>
</test>

変換のために以下の XSLT を試してください。

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:ncb="http://www.namcobandai.com/NS" xmlns:sqe="http://www.squareenix.com/NS">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
    <fo:root>
        <!-- overall layout -->
        <fo:layout-master-set>
            <fo:simple-page-master master-name="coverPage">
                <fo:region-body/>
                <fo:region-before   extent="1in" />
                <fo:region-after    extent="1in" />
                <fo:region-start    extent="1in" />
                <fo:region-end  extent="1in" />
            </fo:simple-page-master>

            <fo:simple-page-master master-name="contentPage">
                <fo:region-body/>
                <fo:region-before   extent="1in" background-color="#0000FF" />
                <fo:region-after    extent="1in" background-color="#0000FF" />
                <fo:region-start/>
                <fo:region-end/>
            </fo:simple-page-master>
        </fo:layout-master-set>
        <!-- page content -->
        <fo:page-sequence master-reference="coverPage">
            <fo:flow flow-name="xsl-region-body">
                <fo:block margin-top="2.5in" text-align="center"><fo:external-graphic content-height="scale-to-fit" height="2.5in" src="ovgsLogo.jpg" /></fo:block>
                <fo:block font-weight="bold" text-align="center">Greetings all yee gamers!</fo:block>
            </fo:flow>
        </fo:page-sequence>

        <xsl:for-each select="../upcoming/*[local-name(.)='game']">
            <fo:page-sequence master-reference="contentPage">
                <fo:static-content flow-name="xsl-region-before">
                    <fo:block margin-top="0.3in" text-align="center">OVGS Upcoming Games</fo:block>
                </fo:static-content>

                <fo:static-content flow-name="xsl-region-after">
                    <fo:block margin-top="0.3in" text-align="center">Page <fo:page-number /></fo:block>
                </fo:static-content>

                <fo:flow flow-name="xsl-region-body">
                    <fo:block font-size="24pt" font-weight="bold" text-align="center" margin-top="2.5in" color="#FF0000"><xsl:value-of select="*[local-name(.)='title']" /></fo:block>
                    <fo:block text-align="center" margin-top="0.2in"><fo:external-graphic content-height="scale-to-fit" height="3in"><xsl:attribute name="src">url('<xsl:value-of select="*[local-name(.)='cover']" />')</xsl:attribute></fo:external-graphic></fo:block>
                    <fo:block font-weight="bold" text-align="center" margin-top="0.3in">Published by <xsl:value-of select="*[local-name(.)='publisher']" /></fo:block>
                    <fo:block font-weight="bold" text-align="center">Developed by <xsl:value-of select="*[local-name(.)='developer']" /></fo:block>
                    <fo:block font-weight="bold" text-align="center"><xsl:value-of select="*[local-name(.)='genre']" /></fo:block>
                    <fo:block font-weight="bold" text-align="center">Released on <xsl:value-of select="*[local-name(.)='releaseDate']/*[local-name(.)='dd']" />/<xsl:value-of select="*[local-name(.)='releaseDate']/*[local-name(.)='mm']" />/<xsl:value-of select="*[local-name(.)='releaseDate']/*[local-name(.)='yyyy']" /></fo:block>
                    <fo:block font-weight="bold" text-align="center">
                        Available on <xsl:value-of select="*[local-name(.)='platforms']/*[local-name(.)='platform[1]']" /><xsl:for-each select="*[local-name(.)='platforms']/*[local-name(.)='platform']">
                        <xsl:if test="position() != last() and position() != 1">, <xsl:value-of select="." /></xsl:if></xsl:for-each> and <xsl:value-of select="*[local-name(.)='platforms']/*[local-name(.)='platform[last()]']" />
                    </fo:block>
                    <fo:block text-align="center" background-color="#9900FF" margin-top="0.3in" margin-left="1in" margin-right="1in"><xsl:value-of select="*[local-name(.)='esrbRating']" /></fo:block>
                </fo:flow>
            </fo:page-sequence>
        </xsl:for-each>

        <xsl:for-each select="ovgs/upcoming/*[local-name(.)='game']">
            <fo:page-sequence master-reference="contentPage">
                <fo:static-content flow-name="xsl-region-before">
                    <fo:block margin-top="0.3in" text-align="center">OVGS Upcoming Games</fo:block>
                </fo:static-content>

                <fo:static-content flow-name="xsl-region-after">
                    <fo:block margin-top="0.3in" text-align="center">Page <fo:page-number /></fo:block>
                </fo:static-content>

                <fo:flow flow-name="xsl-region-body">
                    <fo:block font-size="24pt" font-weight="bold" text-align="center" margin-top="2.5in" color="#FF0000"><xsl:value-of select="*[local-name(.)='title']" /></fo:block>
                    <fo:block text-align="center" margin-top="0.2in"><fo:external-graphic content-height="scale-to-fit" height="3in"><xsl:attribute name="src">url('<xsl:value-of select="*[local-name(.)='cover']" />')</xsl:attribute></fo:external-graphic></fo:block>
                    <fo:block font-weight="bold" text-align="center" margin-top="0.3in">Published by <xsl:value-of select="*[local-name(.)='publisher']" /></fo:block>
                    <fo:block font-weight="bold" text-align="center">Developed by <xsl:value-of select="*[local-name(.)='developer']" /></fo:block>
                    <fo:block font-weight="bold" text-align="center"><xsl:value-of select="*[local-name(.)='genre']" /></fo:block>
                    <fo:block font-weight="bold" text-align="center">Released on <xsl:value-of select="*[local-name(.)='releaseDate']/*[local-name(.)='dd']" />/<xsl:value-of select="*[local-name(.)='releaseDate']/*[local-name(.)='mm']" />/<xsl:value-of select="*[local-name(.)='releaseDate']/*[local-name(.)='yyyy']" /></fo:block>
                    <fo:block font-weight="bold" text-align="center">
                        Available on <xsl:value-of select="*[local-name(.)='platforms']/*[local-name(.)='platform[1]']" /><xsl:for-each select="*[local-name(.)='platforms']/*[local-name(.)='platform']">
                        <xsl:if test="position() != last() and position() != 1">, <xsl:value-of select="." /></xsl:if></xsl:for-each> and <xsl:value-of select="*[local-name(.)='platforms']/*[local-name(.)='platform[last()]']" />
                    </fo:block>
                    <fo:block text-align="center" background-color="#9900FF" margin-top="0.3in" margin-left="1in" margin-right="1in"><xsl:value-of select="*[local-name(.)='esrbRating']" /></fo:block>
                </fo:flow>
            </fo:page-sequence>
        </xsl:for-each>

    </fo:root>
</xsl:template>
</xsl:stylesheet>
于 2013-05-16T12:25:21.990 に答える