0

I am trying to find the "source" element in the xml file but the XSLT code can't find the source element in the XML. Any thoughts on why the XSLT is not working and finding the source element?

XSLT:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"  exclude-result-prefixes="msxsl">
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>




      <xsl:template match="source">

            <xsl:apply-templates select="@* | node()"/>
            <xsl:apply-templates select="Target"/>

    </xsl:template>



</xsl:stylesheet>

XML File:

<?xml version="1.0" encoding="utf-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:sap="http://www.sap.com" xmlns:xhtml="http://www.w3.ogr/1999/xhtml" xmlns:w="http://www.sap.com/w">
    <file datatype="x-application/dsl universe" original="file:/C:/Users/Cost%20Center%20Hierarchy.blx" product-name="SAP Businessobjects Enterprise XI 4.0" source-language="en-US" target-language="pl-PL">
        <header>
            <phase-group>
                <phase process-name="devel" phase-name="devel" tool-id="x-sap-translation-management-tool" />
            </phase-group>
            <tool tool-name="Translation Management Tool" tool-id="x-sap-translation-management-tool" tool-version="XI 4.0" tool-company="SAP Business Objects " />
            <sap:localization-properties>
                <formats />
                <sap:locale-attribute visible="0" fallback="0" modified="0" />
            </sap:localization-properties>
        </header>
        <body>
            <group id="Universe:_7lB2dhEaEeSA04VtNpazeQ">
                <trans-unit id="Universe:_7lB2dhEaEeSA04VtNpazeQ?name" datatype="plaintext">
                    <source>XYZ Hierarchy</source>
                </trans-unit>
                <group>
                    <group id="Folder:_7lB2eREaEeSA04VtNpazeQ">
                        <trans-unit id="Folder:_7lB2eREaEeSA04VtNpazeQ?name" datatype="plaintext">
                            <source>Cost Center Hierarchy</source>
                        </trans-unit>
                        <group id="Dimension:_7lB2ehEaEeSA04VtNpazeQ">
                            <trans-unit id="Dimension:_7lB2ehEaEeSA04VtNpazeQ?name" datatype="plaintext">
                                <source>XYZ Area</source>
                            </trans-unit>
                        </group>
                </group>
            </group>
        </body>
    </file>
</xliff>

Thank you for the help in advanced.

EP244
  • 1
  • 1
  • You have two problems: (1) your template does not match anything because the `source` elements are in the XML's default namespace and (2) `` doesn't do anything because `Target` is not a child of `source` (in fact, it doesn't exist anywhere in your XML). – michael.hor257k Feb 19 '20 at 22:13

1 Answers1

0

You don't have an element called source. You do have an element called urn:oasis:names:tc:xliff:document:1.2: source. The namespace of an XML node always matters, and you've specified by the xmlns attribute in the document that any element not otherwise specified is in this namespace.

To fix this problem, include the namespace with a prefix:

xmlns:some prefix="urn:oasis:names:tc:xliff:document:1.2"

and reference the desired element by this prefix:

<xsl:template match="myprefix:source">

Tom W
  • 5,108
  • 4
  • 30
  • 52