具有名称空间的XSLT

时间:2018-07-26 12:14:56

标签: xml xslt xml-parsing xslt-1.0 xslt-2.0

我是XSL和XSLT的新手。我正在尝试使用xslt将xml转换为xml。如果输入的xml文件在名称空间下包含内容,则它将不起作用。如果删除以下名称空间,则xslt将成功转换xml。 xmlns =“ http://www.omg.org/spec/ReqIF/20110401/reqif.xsd” xsi:schemaLocation =“ http://www.omg.org/spec/ReqIF/20110401/reqif.xsd”

可以帮您找到相同的解决方案吗?输入的xml&xsl文件为:

     <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<data-set xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.omg.org/spec/ReqIF/20110401/reqif.xsd" xmlns:xhtml="http://www.w3.org/1999/xhtml"
    xsi:schemaLocation="http://www.omg.org/spec/ReqIF/20110401/reqif.xsd">
    <REQ-IF>
        <CORE-CONTENT>
            <REQ-IF-CONTENT>
                <SPEC-OBJECTS>
                    <SPEC-OBJECT>
                        <VALUES>
                            <ATTRIBUTE-VALUE-XHTML>
                                <THE-VALUE>
                                    <div>example_task1</div>
                                </THE-VALUE>
                            </ATTRIBUTE-VALUE-XHTML>
                        </VALUES>
                    </SPEC-OBJECT>
                </SPEC-OBJECTS>
            </REQ-IF-CONTENT>
        </CORE-CONTENT>
    </REQ-IF>
</data-set>


          <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:output method="xml" indent="yes" />    
    <xsl:template match="/">
        <uma:test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:uma="http://www.eclipse.org/epf/uma/1.0.6" tool="rmc=7.5.0;epf=1.5.0">
            <MethodElementProperty name="library_synFree"
                value="true" />
            <Plugin name="example_plugin" userChangeable="true"
                id="_plugin1">
                <Package xsi:type="uma:ContentPackage" name="example_package"
                    id="_package1">
                    <xsl:for-each select="REQ-IF/CORE-CONTENT/REQ-IF-CONTENT/SPEC-OBJECTS/SPEC-OBJECT/VALUES/ATTRIBUTE-VALUE-XHTML/THE-VALUE">
                        <Element>
                            <xsl:attribute name="xsi:type">
                                <xsl:text>uma:Task</xsl:text>
                            </xsl:attribute>

                            <xsl:attribute name="name">
                                    <xsl:value-of select="div" />
                                </xsl:attribute>

                            <xsl:attribute name="presentationName">
                                <xsl:value-of select="div" />
                            </xsl:attribute>
                            <xsl:attribute name="id">
                                <xsl:value-of select="div" />
                            </xsl:attribute>
                        </Element>
                    </xsl:for-each>
                </Package>
            </Plugin>
        </uma:test>
    </xsl:template>
</xsl:stylesheet> 

0 个答案:

没有答案