如何将源xml中的所有命名空间复制/继承到样式表中?

时间:2015-12-11 09:36:31

标签: xml xslt namespaces

我输入了xml文件,其中声明了多个名称空间。为了使样式表能够处理带前缀的元素,我需要手动将输入xml的名称空间声明复制到样式表。

我的问题是:是否有更优雅的方式让样式表知道命名空间形成输入xml?换句话说,从输入xml继承那些名称空间声明。

编辑1 输入xml名为 content.xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:anim="urn:oasis:names:tc:opendocument:xmlns:animation:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:db="urn:oasis:names:tc:opendocument:xmlns:database:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:smil="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink" office:version="1.2">
    <office:font-face-decls>
        <style:font-face style:name="Liberation Serif" svg:font-family="Liberation Serif" style:font-family-generic="roman" style:font-pitch="variable" svg:panose-1="2 2 6 3 5 4 5 2 3 4"/>
        <style:font-face style:name="SimSun" svg:font-family="SimSun" style:font-family-generic="system" style:font-pitch="variable" svg:panose-1="2 1 6 0 3 1 1 1 1 1"/>
        <style:font-face style:name="Mangal" svg:font-family="Mangal" style:font-family-generic="roman" style:font-pitch="variable" svg:panose-1="2 4 5 3 5 2 3 3 2 2"/>
        <style:font-face style:name="Calibri Light" svg:font-family="Calibri Light" style:font-family-generic="swiss" style:font-pitch="variable" svg:panose-1="2 15 3 2 2 2 4 3 2 4"/>
        <style:font-face style:name="F" svg:font-family="F" style:font-family-generic="system" style:font-pitch="variable"/>
        <style:font-face style:name="Liberation Sans" svg:font-family="Liberation Sans" style:font-family-generic="swiss" style:font-pitch="variable" svg:panose-1="2 11 6 4 2 2 2 2 2 4"/>
        <style:font-face style:name="Microsoft YaHei" svg:font-family="Microsoft YaHei" style:font-family-generic="swiss" style:font-pitch="variable" svg:panose-1="2 11 5 3 2 2 4 2 2 4"/>
        <style:font-face style:name="Times New Roman" svg:font-family="Times New Roman" style:font-family-generic="roman" style:font-pitch="variable" svg:panose-1="2 2 6 3 5 4 5 2 3 4"/>
        <style:font-face style:name="DeusEx" svg:font-family="DeusEx" style:font-family-generic="roman" style:font-pitch="variable"/>
        <style:font-face style:name="Cambria" svg:font-family="Cambria" style:font-family-generic="roman" style:font-pitch="variable" svg:panose-1="2 4 5 3 5 4 6 3 2 4"/>
        <style:font-face style:name="Arial" svg:font-family="Arial" style:font-family-generic="swiss" style:font-pitch="variable" svg:panose-1="2 11 6 4 2 2 2 2 2 4"/>
        <style:font-face style:name="Calibri" svg:font-family="Calibri" style:font-family-generic="swiss" style:font-pitch="variable" svg:panose-1="2 15 5 2 2 2 4 3 2 4"/>
    </office:font-face-decls>
    <office:automatic-styles>
        <style:style style:name="P1" style:parent-style-name="Style2" style:master-page-name="MP0" style:family="paragraph">
            <style:paragraph-properties fo:break-before="page" fo:margin-top="0in" fo:margin-bottom="0in"/>
        </style:style>
        <style:style style:name="T2" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000"/>
        </style:style>
        <style:style style:name="T3" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000" fo:language="en" fo:country="US"/>
        </style:style>
        <style:style style:name="T4" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000"/>
        </style:style>
        <style:style style:name="T5" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000" fo:language="en" fo:country="US"/>
        </style:style>
        <style:style style:name="T6" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000"/>
        </style:style>
        <style:style style:name="T7" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000" fo:language="en" fo:country="US"/>
        </style:style>
        <style:style style:name="T8" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000"/>
        </style:style>
        <style:style style:name="T9" style:parent-style-name="BoldStyle" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000"/>
        </style:style>
        <style:style style:name="T10" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000"/>
        </style:style>
        <style:style style:name="T11" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:language-asian="bg" style:country-asian="BG" style:language-complex="ar" style:country-complex="SA"/>
        </style:style>
        <style:style style:name="T12" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000"/>
        </style:style>
        <style:style style:name="T13" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000" fo:language="en" fo:country="US"/>
        </style:style>
        <style:style style:name="T14" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000"/>
        </style:style>
        <style:style style:name="T15" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000" fo:language="en" fo:country="US"/>
        </style:style>
        <style:style style:name="T16" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000"/>
        </style:style>
        <style:style style:family="graphic" style:name="a0" style:parent-style-name="Graphics">
            <style:graphic-properties fo:border="0.01042in none" fo:background-color="transparent" fo:clip="rect(0in, 0in, 0in, 0in)"/>
        </style:style>
    </office:automatic-styles>
    <office:body>
        <office:text text:use-soft-page-breaks="true">
            <text:p text:style-name="P1"/>
            <text:p text:style-name="Title">
                <text:span text:style-name="T2">Запознаване със<text:s/></text:span>
                <text:span text:style-name="T3">JTAG<text:s/></text:span>
                <text:span text:style-name="T4">протокол за програмиране на<text:s/></text:span>
                <text:span text:style-name="T5">MSP430</text:span>
                <text:span text:style-name="T6">Запознаване с функционалността на<text:s/></text:span>
                <text:span text:style-name="T7">Real Time Clock.</text:span>
            </text:p>
            <text:p text:style-name="Standard"/>
            <text:p text:style-name="Subtitle">
                <text:span text:style-name="T8">Създаване на<text:s/></text:span>
                <text:span text:style-name="T9">часовник</text:span>
                <text:span text:style-name="T10"><text:s/>с календар в реално време.</text:span>
            </text:p>
            <text:p text:style-name="Standard">
                <text:span text:style-name="T11">
                    <draw:frame draw:style-name="a0" draw:name="Picture 1" text:anchor-type="as-char" svg:x="0in" svg:y="0in" svg:width="6.6875in" svg:height="3.11458in" style:rel-width="scale" style:rel-height="scale">
                        <draw:image xlink:href="media/image1.png" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
                        <svg:title/>
                        <svg:desc/>
                    </draw:frame>
                </text:span>
            </text:p>
            <text:h text:style-name="Heading1" text:outline-level="1">
                <text:span text:style-name="T12">Запознаване с<text:s/></text:span>
                <text:span text:style-name="T13">UART<text:s/></text:span>
                <text:span text:style-name="T14">периферията на</text:span>
                <text:span text:style-name="T15"><text:s/>MSP430F5438.</text:span>
            </text:h>
            <text:p text:style-name="Standard"/>
            <text:h text:style-name="Heading2" text:outline-level="2">
                <text:span text:style-name="T16">Създаване на график за аларма и реализиране на прекъсвания по зададени час и дата.</text:span>
            </text:h>
        </office:text>
    </office:body>
</office:document-content>

样式表:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:anim="urn:oasis:names:tc:opendocument:xmlns:animation:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:db="urn:oasis:names:tc:opendocument:xmlns:database:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:smil="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink" office:version="1.2">
    <office:font-face-decls>
        <style:font-face style:name="Liberation Serif" svg:font-family="Liberation Serif" style:font-family-generic="roman" style:font-pitch="variable" svg:panose-1="2 2 6 3 5 4 5 2 3 4"/>
        <style:font-face style:name="SimSun" svg:font-family="SimSun" style:font-family-generic="system" style:font-pitch="variable" svg:panose-1="2 1 6 0 3 1 1 1 1 1"/>
        <style:font-face style:name="Mangal" svg:font-family="Mangal" style:font-family-generic="roman" style:font-pitch="variable" svg:panose-1="2 4 5 3 5 2 3 3 2 2"/>
        <style:font-face style:name="Calibri Light" svg:font-family="Calibri Light" style:font-family-generic="swiss" style:font-pitch="variable" svg:panose-1="2 15 3 2 2 2 4 3 2 4"/>
        <style:font-face style:name="F" svg:font-family="F" style:font-family-generic="system" style:font-pitch="variable"/>
        <style:font-face style:name="Liberation Sans" svg:font-family="Liberation Sans" style:font-family-generic="swiss" style:font-pitch="variable" svg:panose-1="2 11 6 4 2 2 2 2 2 4"/>
        <style:font-face style:name="Microsoft YaHei" svg:font-family="Microsoft YaHei" style:font-family-generic="swiss" style:font-pitch="variable" svg:panose-1="2 11 5 3 2 2 4 2 2 4"/>
        <style:font-face style:name="Times New Roman" svg:font-family="Times New Roman" style:font-family-generic="roman" style:font-pitch="variable" svg:panose-1="2 2 6 3 5 4 5 2 3 4"/>
        <style:font-face style:name="DeusEx" svg:font-family="DeusEx" style:font-family-generic="roman" style:font-pitch="variable"/>
        <style:font-face style:name="Cambria" svg:font-family="Cambria" style:font-family-generic="roman" style:font-pitch="variable" svg:panose-1="2 4 5 3 5 4 6 3 2 4"/>
        <style:font-face style:name="Arial" svg:font-family="Arial" style:font-family-generic="swiss" style:font-pitch="variable" svg:panose-1="2 11 6 4 2 2 2 2 2 4"/>
        <style:font-face style:name="Calibri" svg:font-family="Calibri" style:font-family-generic="swiss" style:font-pitch="variable" svg:panose-1="2 15 5 2 2 2 4 3 2 4"/>
    </office:font-face-decls>
    <office:automatic-styles>
        <style:style style:name="P1" style:parent-style-name="Style2" style:master-page-name="MP0" style:family="paragraph">
            <style:paragraph-properties fo:break-before="page" fo:margin-top="0in" fo:margin-bottom="0in"/>
        </style:style>
        <style:style style:name="T2" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000"/>
        </style:style>
        <style:style style:name="T3" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000" fo:language="en" fo:country="US"/>
        </style:style>
        <style:style style:name="T4" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000"/>
        </style:style>
        <style:style style:name="T5" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000" fo:language="en" fo:country="US"/>
        </style:style>
        <style:style style:name="T6" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000"/>
        </style:style>
        <style:style style:name="T7" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000" fo:language="en" fo:country="US"/>
        </style:style>
        <style:style style:name="T8" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000"/>
        </style:style>
        <style:style style:name="T9" style:parent-style-name="BoldStyle" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000"/>
        </style:style>
        <style:style style:name="T10" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000"/>
        </style:style>
        <style:style style:name="T11" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:language-asian="bg" style:country-asian="BG" style:language-complex="ar" style:country-complex="SA"/>
        </style:style>
        <style:style style:name="T12" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000"/>
        </style:style>
        <style:style style:name="T13" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000" fo:language="en" fo:country="US"/>
        </style:style>
        <style:style style:name="T14" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000"/>
        </style:style>
        <style:style style:name="T15" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000" fo:language="en" fo:country="US"/>
        </style:style>
        <style:style style:name="T16" style:parent-style-name="DefaultParagraphFont" style:family="text">
            <style:text-properties style:font-name="Cambria" style:font-name-complex="Arial" fo:color="#000000"/>
        </style:style>
        <style:style style:family="graphic" style:name="a0" style:parent-style-name="Graphics">
            <style:graphic-properties fo:border="0.01042in none" fo:background-color="transparent" fo:clip="rect(0in, 0in, 0in, 0in)"/>
        </style:style>
    </office:automatic-styles>
    <office:body>
        <office:text text:use-soft-page-breaks="true">
            <text:p text:style-name="P1"/>
            <text:p text:style-name="Title">
                <text:span text:style-name="T2">Запознаване със<text:s/></text:span>
                <text:span text:style-name="T3">JTAG<text:s/></text:span>
                <text:span text:style-name="T4">протокол за програмиране на<text:s/></text:span>
                <text:span text:style-name="T5">MSP430</text:span>
                <text:span text:style-name="T6">Запознаване с функционалността на<text:s/></text:span>
                <text:span text:style-name="T7">Real Time Clock.</text:span>
            </text:p>
            <text:p text:style-name="Standard"/>
            <text:p text:style-name="Subtitle">
                <text:span text:style-name="T8">Създаване на<text:s/></text:span>
                <text:span text:style-name="T9">часовник</text:span>
                <text:span text:style-name="T10"><text:s/>с календар в реално време.</text:span>
            </text:p>
            <text:p text:style-name="Standard">
                <text:span text:style-name="T11">
                    <draw:frame draw:style-name="a0" draw:name="Picture 1" text:anchor-type="as-char" svg:x="0in" svg:y="0in" svg:width="6.6875in" svg:height="3.11458in" style:rel-width="scale" style:rel-height="scale">
                        <draw:image xlink:href="media/image1.png" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
                        <svg:title/>
                        <svg:desc/>
                    </draw:frame>
                </text:span>
            </text:p>
            <text:h text:style-name="Heading1" text:outline-level="1">
                <text:span text:style-name="T12">Запознаване с<text:s/></text:span>
                <text:span text:style-name="T13">UART<text:s/></text:span>
                <text:span text:style-name="T14">периферията на</text:span>
                <text:span text:style-name="T15"><text:s/>MSP430F5438.</text:span>
            </text:h>
            <text:p text:style-name="Standard"/>
            <text:h text:style-name="Heading2" text:outline-level="2">
                <text:span text:style-name="T16">Създаване на график за аларма и реализиране на прекъсвания по зададени час и дата.</text:span>
            </text:h>
        </office:text>
    </office:body>
</office:document-content>

我想要的结果是实现的。输出不是问题。问题是每个输入文件可能包含不同的命名空间声明,因此对于我需要处理的每个新输入xml,我必须手动将命名空间声明从xml文件复制到xsl文件。

到目前为止,我手动输入了命名空间声明。但它们往往变得越来越多。

请原谅我可怜的英语!

0 个答案:

没有答案