xmlxsltxml-namespacesxsi

XSLT get the right GUID from XMLNS/XML


I try to get the correct GGUID out of my XMLNS/XML file.

I want the right GGUID so I can Log some actions on my Process with this ID.

Here is my XMLNS/XML:

<?xml version="1.0"?>
<s:Envelope>
    <s:Body>
        <element:saveAndReturnObjectResponse xmlns:element="http://some-link">
            <element:return>
                <element_II:fields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:element_II="http://some-link" xsi:type="element_II:GGUIDField">
                    <element_II:name>GGUID</element_II:name>
                    <element_II:fieldType>GGUID</element_II:fieldType>
                    <element_II:value>D6443FCE29334414AF2DC5A30C90506C</element_II:value>
                </element_II:fields>

                <element_II:fields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:element_II="http://some-link" xsi:type="element_II:GGUIDField">
                    <element_II:name>OWNERGUID</element_II:name>
                    <element_II:fieldType>GGUID</element_II:fieldType>
                    <element_II:value>00000000000000000000000000000000</element_II:value>
                </element_II:fields>
            </element:return>
        </element:saveAndReturnObjectResponse>
    </s:Body>
</s:Envelope>

The XMLNS/XML is Statyc, so no changes can be done on this.

What I treid is:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:some-element="http://some-link" xmlns:some-element_II="http://some-link" xmlns:ns1="http://some-link" version="2.0">
    <xsl:output media-type="text/xml" method="xml"></xsl:output>
    <xsl:template match="/">
        <xsl:if test="/s:Envelope/s:Body/element:saveAndReturnObjectResponse/element:return/element_II:fields[@xsi:type='element_II:GGUIDField']/element_II:name='GGUID'">
            <xsl:value-of select="CONCAT('0x',/s:Envelope/s:Body/element:saveAndReturnObjectResponse/element:return/element_II:fields[@xsi:type='element_II:GGUIDField']/element_II:value)"></xsl:value-of>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>

So far so good I thought but my output is following:

<?xml version="1.0"?>
<root>
    <element_II:value>0xD6443FCE29334414AF2DC5A30C90506C 0x00000000000000000000000000000000</element_II:value>
</root>

What I really expected for my output is:

<?xml version="1.0"?>
<root>
    <element_II:value>0xD6443FCE29334414AF2DC5A30C90506C</element_II:value>
</root>

Solution

  • both elements are matches for

    /s:Envelope/s:Body/element:saveAndReturnObjectResponse/element:return/element_II:fields[@xsi:type='element_II:GGUIDField']/element_II:value
    

    so you'll get 2 results...

    if you just want the first one try also filtering for

    element_II:name='GGUID'
    

    e.g.

    /s:Envelope/s:Body/element:saveAndReturnObjectResponse/element:return/element_II:fields[@xsi:type='element_II:GGUIDField'][element_II:name='GGUID']/element_II:value