1

I have the XML in the below format

<?xml version="1.0" encoding="utf-8"?>
<Data Schema="RSXML4.0" xmlns="http://schemas.riversand.com/mdmcenter"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://schemas.riversand.com/mdmcenter/RSXml4.0.xsd">
    <Entities>
<Entity Id="347" ExternalId="SSI1006"
            LongName="School Smart Hand Held Rustproof Carbon Steel Pencil Sharpener, Assorted Color, Pack of 24"
            EntityTypeId="18" EntityTypeName="Parent SKU" ContainerId="2"
            ContainerName="Collaboration Master" OrganizationName="DL" CategoryId="360"
            CategoryName="Sharpners" CategoryLongName="Sharpners"
            CategoryPath="SchoolSupplies»School_Office_Supplies»Sharpners" CategoryLongNamePath=""
            ParentEntityId="360" ParentExternalId="Sharpners" ParentExtensionEntityId="0"
            ParentExtensionEntityExternalId="" ParentExtensionEntityContainerId="0"
            ParentExtensionEntityContainerName="" ParentExtensionEntityCategoryId="0"
            ParentExtensionEntityCategoryPath="" ParentExtensionEntityCategoryLongNamePath=""
            Locale="en_WW" Action="Add">
            <Attributes>
                <Attribute Id="4039" Name="Parent SKU #" LongName="Product Number"
                    InstanceRefId="-1" Sequence="-1" AttributeParentId="4000"
                    AttributeParentName="Core Attribute Group" AttributeType="Simple"
                    AttributeDataType="String" Locale="en_WW" Action="Add">
                    <Values>
                        <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue=""
                            HasInvalidValue="False" Locale="en_WW" Action="Add"
                            ><![CDATA[9-07466-030]]></Value>
                    </Values>
                </Attribute>
                <Attribute Id="4040" Name="Product Name" LongName="Product Name" InstanceRefId="-1"
                    Sequence="-1" AttributeParentId="4000"
                    AttributeParentName="Core Attribute Group" AttributeType="Simple"
                    AttributeDataType="String" Locale="en_WW" Action="Add">
                    <Values>
                        <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue=""
                            HasInvalidValue="False" Locale="en_WW" Action="Add"
                            ><![CDATA[School Smart Hand Held Rustproof Carbon Steel Pencil Sharpener]]></Value>
                    </Values>
                </Attribute>
                <Attribute Id="4041" Name="SKU Dimensions" LongName="SKU Dimensions"
                    InstanceRefId="-1" Sequence="-1" AttributeParentId="4000"
                    AttributeParentName="Core Attribute Group" AttributeType="Simple"
                    AttributeDataType="String" Locale="en_WW" Action="Add">
                    <Values>
                        <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue=""
                            HasInvalidValue="False" Locale="en_WW" Action="Add"
                            ><![CDATA[3/4 in x 1 in x 1/2 in]]></Value>
                    </Values>
                </Attribute>
                <Attribute Id="4042" Name="MSRP" LongName="MSRP" InstanceRefId="-1" Sequence="-1"
                    AttributeParentId="4000" AttributeParentName="Core Attribute Group"
                    AttributeType="Simple" AttributeDataType="Decimal" Locale="en_WW" Action="Add">
                    <Values>
                        <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue=""
                            HasInvalidValue="False" Locale="en_WW" Action="Add"
                            ><![CDATA[2.49]]></Value>
                    </Values>
                </Attribute>
                <Attribute Id="4045" Name="Collection" LongName="Collection" InstanceRefId="-1"
                    Sequence="-1" AttributeParentId="4000"
                    AttributeParentName="Core Attribute Group" AttributeType="Simple"
                    AttributeDataType="String" Locale="en_WW" Action="Add">
                    <Values>
                        <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue=""
                            HasInvalidValue="False" Locale="en_WW" Action="Add"
                            ><![CDATA[School Smart]]></Value>
                    </Values>
                </Attribute>
                <Attribute Id="4047" Name="UPC" LongName="UPC" InstanceRefId="-1" Sequence="-1"
                    AttributeParentId="4000" AttributeParentName="Core Attribute Group"
                    AttributeType="Simple" AttributeDataType="String" Locale="en_WW" Action="Add">
                    <Values>
                        <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue=""
                            HasInvalidValue="False" Locale="en_WW" Action="Add"
                            ><![CDATA[892030475006]]></Value>
                    </Values>
                </Attribute>
                <Attribute Id="4049" Name="Short Description" LongName="Short Description"
                    InstanceRefId="-1" Sequence="-1" AttributeParentId="4001"
                    AttributeParentName="Marketing Attribute Group" AttributeType="Simple"
                    AttributeDataType="String" Locale="en_WW" Action="Add">
                    <Values>
                        <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue=""
                            HasInvalidValue="False" Locale="en_WW" Action="Add"
                            ><![CDATA[School Smart hand Pencil Sharpener features plastic housing with hardened and honed rust-proof carbon steel blade.]]></Value>
                    </Values>
                </Attribute>
                <Attribute Id="4050" Name="Long Description" LongName="Long Description"
                    InstanceRefId="-1" Sequence="-1" AttributeParentId="4001"
                    AttributeParentName="Marketing Attribute Group" AttributeType="Simple"
                    AttributeDataType="String" Locale="en_WW" Action="Add">
                    <Values>
                        <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue=""
                            HasInvalidValue="False" Locale="en_WW" Action="Add"
                            ><![CDATA[School Smart hand Pencil Sharpener features plastic housing with hardened and honed rust-proof carbon steel blade. Designed for sharpening of pencils. Hand pencil sharpener comes in assorted colors and is sold as 24 per pack.]]></Value>
                    </Values>
                </Attribute>
                <Attribute Id="4122" Name="A-Assets" LongName="Assets" InstanceRefId="-1"
                    Sequence="-1" AttributeParentId="4003"
                    AttributeParentName="Media Attribute Group" AttributeType="ComplexCollection"
                    AttributeDataType="String" Locale="en_WW" Action="Add">
                    <Attributes>
                        <Attribute Id="4122" Name="A-Assets Instance Record"
                            LongName="Assets Instance Record" InstanceRefId="293" Sequence="0"
                            AttributeParentId="4003" AttributeParentName="Media Attribute Group"
                            AttributeType="Complex" AttributeDataType="String" Locale="en_WW"
                            Action="Add">
                            <Attributes>
                                <Attribute Id="4126" Name="A-AssetDescription"
                                    LongName="AssetDescription" InstanceRefId="-1" Sequence="-1"
                                    AttributeParentId="4122" AttributeParentName="A-Assets"
                                    AttributeType="Simple" AttributeDataType="String" Locale="en_WW"
                                    Action="Add">
                                    <Values>
                                        <Value Id="-1" Uom="" ValueRefId="0" Sequence="-1"
                                            DisplayValue="" HasInvalidValue="False" Locale="en_WW"
                                            Action="Add"><![CDATA[]]></Value>
                                    </Values>
                                </Attribute>
                                <Attribute Id="4127" Name="A-AssetDisplayName"
                                    LongName="AssetDisplayName" InstanceRefId="-1" Sequence="-1"
                                    AttributeParentId="4122" AttributeParentName="A-Assets"
                                    AttributeType="Simple" AttributeDataType="String" Locale="en_WW"
                                    Action="Add">
                                    <Values>
                                        <Value Id="-1" Uom="" ValueRefId="0" Sequence="-1"
                                            DisplayValue="" HasInvalidValue="False" Locale="en_WW"
                                            Action="Add"><![CDATA[]]></Value>
                                    </Values>
                                </Attribute>
                                <Attribute Id="4128" Name="A-AssetFileName" LongName="AssetFileName"
                                    InstanceRefId="-1" Sequence="-1" AttributeParentId="4122"
                                    AttributeParentName="A-Assets" AttributeType="Simple"
                                    AttributeDataType="String" Locale="en_WW" Action="Add">
                                    <Values>
                                        <Value Id="-1" Uom="" ValueRefId="0" Sequence="-1"
                                            DisplayValue="" HasInvalidValue="False" Locale="en_WW"
                                            Action="Add"
                                            ><![CDATA[SSI1006_SchoolSmart Sharpener_1.jpg]]></Value>
                                    </Values>
                                </Attribute>
                                <Attribute Id="4129" Name="A-AssetID" LongName="AssetID"
                                    InstanceRefId="-1" Sequence="-1" AttributeParentId="4122"
                                    AttributeParentName="A-Assets" AttributeType="Simple"
                                    AttributeDataType="String" Locale="en_WW" Action="Add">
                                    <Values>
                                        <Value Id="-1" Uom="" ValueRefId="0" Sequence="-1"
                                            DisplayValue="" HasInvalidValue="False" Locale="en_WW"
                                            Action="Add"
                                            ><![CDATA[991E8697FD394A17A70C0DA7A73ECE87]]></Value>
                                    </Values>
                                </Attribute>
                                <Attribute Id="4130" Name="A-AssetImageThumb"
                                    LongName="AssetImageThumb" InstanceRefId="-1" Sequence="-1"
                                    AttributeParentId="4122" AttributeParentName="A-Assets"
                                    AttributeType="Simple" AttributeDataType="String" Locale="en_WW"
                                    Action="Add">
                                    <Values>
                                        <Value Id="-1" Uom="" ValueRefId="0" Sequence="-1"
                                            DisplayValue="" HasInvalidValue="False" Locale="en_WW"
                                            Action="Add"><![CDATA[]]></Value>
                                    </Values>
                                </Attribute>
                                <Attribute Id="4131" Name="A-AssetImageType"
                                    LongName="AssetImageType" InstanceRefId="-1" Sequence="-1"
                                    AttributeParentId="4122" AttributeParentName="A-Assets"
                                    AttributeType="Simple" AttributeDataType="String" Locale="en_WW"
                                    Action="Add">
                                    <Values>
                                        <Value Id="-1" Uom="" ValueRefId="0" Sequence="-1"
                                            DisplayValue="" HasInvalidValue="False" Locale="en_WW"
                                            Action="Add"><![CDATA[]]></Value>
                                    </Values>
                                </Attribute>
                                <Attribute Id="4132" Name="A-AssetKind" LongName="AssetKind"
                                    InstanceRefId="-1" Sequence="-1" AttributeParentId="4122"
                                    AttributeParentName="A-Assets" AttributeType="Simple"
                                    AttributeDataType="String" Locale="en_WW" Action="Add">
                                    <Values>
                                        <Value Id="-1" Uom="" ValueRefId="0" Sequence="-1"
                                            DisplayValue="" HasInvalidValue="False" Locale="en_WW"
                                            Action="Add"><![CDATA[]]></Value>
                                    </Values>
                                </Attribute>
                                <Attribute Id="4133" Name="A-AssetLocalURL" LongName="AssetLocalURL"
                                    InstanceRefId="-1" Sequence="-1" AttributeParentId="4122"
                                    AttributeParentName="A-Assets" AttributeType="Simple"
                                    AttributeDataType="String" Locale="en_WW" Action="Add">
                                    <Values>
                                        <Value Id="-1" Uom="" ValueRefId="0" Sequence="-1"
                                            DisplayValue="" HasInvalidValue="False" Locale="en_WW"
                                            Action="Add"
                                            ><![CDATA[http://smbpoc.riversand.com:8080/MAM76/assets/1/76E608495D23463EA54B253B1FB1D94C/img/991E8697FD394A17A70C0DA7A73ECE87/SSI1006_SchoolSmart_Sharpener_1.jpg]]></Value>
                                    </Values>
                                </Attribute>
                                <Attribute Id="4134" Name="A-AssetProductDescription"
                                    LongName="AssetProductDescription" InstanceRefId="-1"
                                    Sequence="-1" AttributeParentId="4122"
                                    AttributeParentName="A-Assets" AttributeType="Simple"
                                    AttributeDataType="String" Locale="en_WW" Action="Add">
                                    <Values>
                                        <Value Id="-1" Uom="" ValueRefId="0" Sequence="-1"
                                            DisplayValue="" HasInvalidValue="False" Locale="en_WW"
                                            Action="Add"><![CDATA[]]></Value>
                                    </Values>
                                </Attribute>
                                <Attribute Id="4135" Name="A-AssetRenditions"
                                    LongName="AssetRenditions" InstanceRefId="-1" Sequence="-1"
                                    AttributeParentId="4122" AttributeParentName="A-Assets"
                                    AttributeType="Simple" AttributeDataType="String" Locale="en_WW"
                                    Action="Add">
                                    <Values>
                                        <Value Id="-1" Uom="" ValueRefId="0" Sequence="-1"
                                            DisplayValue="" HasInvalidValue="False" Locale="en_WW"
                                            Action="Add"
                                            ><![CDATA[<?xml version="1.0" encoding="utf-16"?><Renditions />]]></Value>
                                    </Values>
                                </Attribute>
                                <Attribute Id="4136" Name="A-AssetSize" LongName="AssetSize"
                                    InstanceRefId="-1" Sequence="-1" AttributeParentId="4122"
                                    AttributeParentName="A-Assets" AttributeType="Simple"
                                    AttributeDataType="String" Locale="en_WW" Action="Add">
                                    <Values>
                                        <Value Id="-1" Uom="" ValueRefId="0" Sequence="-1"
                                            DisplayValue="" HasInvalidValue="False" Locale="en_WW"
                                            Action="Add"><![CDATA[93194]]></Value>
                                    </Values>
                                </Attribute>
                                <Attribute Id="4137" Name="A-AssetThumbnailURL"
                                    LongName="AssetThumbnailURL" InstanceRefId="-1" Sequence="-1"
                                    AttributeParentId="4122" AttributeParentName="A-Assets"
                                    AttributeType="Simple" AttributeDataType="String" Locale="en_WW"
                                    Action="Add">
                                    <Values>
                                        <Value Id="-1" Uom="" ValueRefId="0" Sequence="-1"
                                            DisplayValue="" HasInvalidValue="False" Locale="en_WW"
                                            Action="Add"
                                            ><![CDATA[http://smbpoc.riversand.com:8080/MAM76/assets/1/76E608495D23463EA54B253B1FB1D94C/img/991E8697FD394A17A70C0DA7A73ECE87/thumb_991E8697FD394A17A70C0DA7A73ECE87.jpg]]></Value>
                                    </Values>
                                </Attribute>
                                <Attribute Id="4138" Name="A-AssetType" LongName="AssetType"
                                    InstanceRefId="-1" Sequence="-1" AttributeParentId="4122"
                                    AttributeParentName="A-Assets" AttributeType="Simple"
                                    AttributeDataType="String" Locale="en_WW" Action="Add">
                                    <Values>
                                        <Value Id="-1" Uom="" ValueRefId="0" Sequence="-1"
                                            DisplayValue="" HasInvalidValue="False" Locale="en_WW"
                                            Action="Add"><![CDATA[img]]></Value>
                                    </Values>
                                </Attribute>
                                <Attribute Id="4139" Name="A-AssetPrimary" LongName="AssetPrimary"
                                    InstanceRefId="-1" Sequence="-1" AttributeParentId="4122"
                                    AttributeParentName="A-Assets" AttributeType="Simple"
                                    AttributeDataType="String" Locale="en_WW" Action="Add">
                                    <Values>
                                        <Value Id="-1" Uom="" ValueRefId="2" Sequence="-1"
                                            DisplayValue="Secondary" HasInvalidValue="False"
                                            Locale="en_WW" Action="Add"
                                            ><![CDATA[Secondary]]></Value>
                                    </Values>
                                </Attribute>
                                <Attribute Id="4140" Name="A-AssetSequence" LongName="AssetSequence"
                                    InstanceRefId="-1" Sequence="-1" AttributeParentId="4122"
                                    AttributeParentName="A-Assets" AttributeType="Simple"
                                    AttributeDataType="Integer" Locale="en_WW" Action="Add">
                                    <Values>
                                        <Value Id="-1" Uom="" ValueRefId="0" Sequence="-1"
                                            DisplayValue="" HasInvalidValue="False" Locale="en_WW"
                                            Action="Add"><![CDATA[1]]></Value>
                                    </Values>
                                </Attribute>
                                <Attribute Id="4142" Name="A-FilePath" LongName="AssetFilePath"
                                    InstanceRefId="-1" Sequence="-1" AttributeParentId="4122"
                                    AttributeParentName="A-Assets" AttributeType="Simple"
                                    AttributeDataType="String" Locale="en_WW" Action="Add">
                                    <Values>
                                        <Value Id="-1" Uom="" ValueRefId="0" Sequence="-1"
                                            DisplayValue="" HasInvalidValue="False" Locale="en_WW"
                                            Action="Add"
                                            ><![CDATA[C:\Users\RSAdmin\Documents\Templates\Print Images\SSI1006_SchoolSmart_Sharpener_1.jpg]]></Value>
                                    </Values>
                                </Attribute>
                            </Attributes>
                        </Attribute>
                    </Attributes>
                </Attribute>
                <Attribute Id="4618" Name="ItemQty" LongName="ItemQty" InstanceRefId="-1"
                    Sequence="-1" AttributeParentId="4000"
                    AttributeParentName="Core Attribute Group" AttributeType="Simple"
                    AttributeDataType="String" Locale="en_WW" Action="Add">
                    <Values>
                        <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue=""
                            HasInvalidValue="False" Locale="en_WW" Action="Add"
                            ><![CDATA[Pack of 24]]></Value>
                    </Values>
                </Attribute>
                <Attribute Id="4619" Name="ItemColor" LongName="ItemColor" InstanceRefId="-1"
                    Sequence="-1" AttributeParentId="4000"
                    AttributeParentName="Core Attribute Group" AttributeType="Simple"
                    AttributeDataType="String" Locale="en_WW" Action="Add">
                    <Values>
                        <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue=""
                            HasInvalidValue="False" Locale="en_WW" Action="Add"
                            ><![CDATA[Assorted]]></Value>
                    </Values>
                </Attribute>
            </Attributes>
            <Relationships/>
        </Entity>
    </Entities>
</Data>

I have multiple such Entity nodes. I need to add an attribute in each 'Entity' node as ProductImage = value of the attribute with the name 'A-AssetFileName'. I need to do this using XSLT. Any help would be appreciated. The below XSLT adds the value of each image value to the same Entity node. I want each Entity node to have their corresponding image value from the attribute with the name 'A-AssetFileName'. For eg: my first entity node should become:

<Entity Id="347" ExternalId="SSI1006"
            LongName="School Smart Hand Held Rustproof Carbon Steel Pencil Sharpener, Assorted Color, Pack of 24"
            EntityTypeId="18" EntityTypeName="Parent SKU" ContainerId="2"
            ContainerName="Collaboration Master" OrganizationName="DL" CategoryId="360"
            CategoryName="Sharpners" CategoryLongName="Sharpners"
            CategoryPath="SchoolSupplies»School_Office_Supplies»Sharpners" CategoryLongNamePath=""
            ParentEntityId="360" ParentExternalId="Sharpners" ParentExtensionEntityId="0"
            ParentExtensionEntityExternalId="" ParentExtensionEntityContainerId="0"
            ParentExtensionEntityContainerName="" ParentExtensionEntityCategoryId="0"
            ParentExtensionEntityCategoryPath="" ParentExtensionEntityCategoryLongNamePath=""
            Locale="en_WW" Action="Add" ProductImage="SSI1006_SchoolSmart Sharpener_1.jpg">

I am using the below XSLT.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:x="http://schemas.riversand.com/mdmcenter">
    <xsl:output omit-xml-declaration="yes" indent="yes" encoding="UTF-8"/>
    <xsl:strip-space elements="*"/>
    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="/x:Data/x:Entities/x:Entity">
        <xsl:for-each select = "/x:Data/x:Entities/x:Entity"> 
        <xsl:copy>

<!--                <xsl:choose>-->
<!--                    <xsl:when test='/x:Data/x:Entities/x:Entity/x:Attributes/x:Attribute/x:Attributes/x:Attribute[@Name = "A-Assets Instance Record"]'>-->
<!--                        <xsl:if test='/x:Data/x:Entities/x:Entity/x:Attributes/x:Attribute/x:Attributes/x:Attribute[@Sequence = "0"]'>-->

                            <xsl:attribute name="ProductImage"> 
                                <xsl:for-each select = "/x:Data/x:Entities/x:Entity/x:Attributes/x:Attribute/x:Attributes/x:Attribute/x:Attributes/x:Attribute[@Name = 'A-AssetFileName']">
                                <xsl:value-of select="."/>
                                </xsl:for-each>
                            </xsl:attribute>

                        <!--</xsl:if>-->
                    <!--</xsl:when>-->
                <!--</xsl:choose>-->
                <!--            <xsl:apply-templates select="@* | node()"/>-->

        </xsl:copy>
        </xsl:for-each>
    </xsl:template>

</xsl:stylesheet>
1
  • It would be helpful if you at least provided an example of the desired output. If you don't have an XSLT to share and aren't sure where to start, that is fine, but at least provide a clear example of the desired output. i.e. The first Entity element would become <Entity Image="abc.jpg"> with any leading/trailing whitespace from the <value> element removed. Commented Aug 24, 2018 at 2:32

2 Answers 2

1

You can start with an identity template that copies the input XML as is to the output.

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

Since you need to add an attribute to the Entity element, a matching template is used. An attribute Image is created within the template with a value corresponding to the value of element Attribute/value within the Entity template. Function normalize-space() is used to get rid of any leading and trailing spaces.

<xsl:template match="Entity">
    <xsl:copy>
        <xsl:attribute name="Image">
            <xsl:value-of select="normalize-space(Attribute/value)" />
        </xsl:attribute>
        <xsl:apply-templates />
    </xsl:copy>
</xsl:template>

Complete XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" />
    <xsl:strip-space elements="*" />

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

    <xsl:template match="Entity">
        <xsl:copy>
            <xsl:attribute name="Image">
                <xsl:value-of select="normalize-space(Attribute/value)" />
            </xsl:attribute>
            <xsl:apply-templates />
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Output is as below. Since the input XML has abc.jpg as a value of both the value elements, the attribute value is the same for both the Entity elements.

<Data>
    <Entities>
        <Entity Image="abc.jpg">
            <Attribute name="abc">
                <value> abc.jpg
                </value>
            </Attribute>
        </Entity>
        <Entity Image="abc.jpg">
            <Attribute name="def">
                <value> abc.jpg
                </value>
            </Attribute>
        </Entity>
    </Entities>
</Data>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Aniket for your reply. But I still have not achieved what I wanted. Please check my question. I have updated with the exact XML and XSLT.
0

You were on the right track, but it seems that you may not quite understand what the context node for a matched template is, and how to use an XPath that is relative from that node.

When the template matches on an /x:Data/x:Entities/x:Entity element, any of the XPath expressions inside of that template will be relative from that element.

If there are multiple x:Entity elements, that template will fire multiple times; once for each of those elements. So, you would not want to use the xs:for-each that selects all of the /x:Data/x:Entities/x:Entity elements with an XPath that "jumps up" to the top of the XML tree to select all of the x:Entity elements. That would have the effect of making a cartesian product.

Similarly, when selecting the value for the attribute, you want to use an XPath that selects the Attribute element relative from the context node (the x:Entity that was matched by the template).

If the structure of those x:Attributes/x:Attribute elements could be vary (sometimes siblings, sometimes descendants), you could use a more generic XPath to select from any of it's descendants with a more generic XPath that filters by the @name: .//x:Attributes/x:Attribute[@Name = 'A-AssetFileName']/x:Values/x:Value

Applying changes to your stylesheet:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:x="http://schemas.riversand.com/mdmcenter">
    <xsl:output omit-xml-declaration="yes" indent="yes" encoding="UTF-8"/>
    <xsl:strip-space elements="*"/>

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

    <xsl:template match="/x:Data/x:Entities/x:Entity">

        <xsl:copy> <!--copy the matched Entity-->
            <xsl:apply-templates select="@*"/> <!--preserve existing attributes-->

            <xsl:attribute name="ProductImage"> 
                <!--Sele the attribute value using a relative path from the matched Entity -->
                <xsl:value-of select="x:Attributes/x:Attribute/x:Attributes/x:Attribute/x:Attributes/x:Attribute[@Name = 'A-AssetFileName']/x:Values/x:Value"/>
<!--If you aren't sure what the nesting structure of the Attributes will be, 
    then just use the descendant axis to look down as many levels as it needs to find it
                <xsl:value-of select=".//x:Attributes/x:Attribute[@Name = 'A-AssetFileName']/x:Values/x:Value"/>
-->
            </xsl:attribute>

            <!--if you don't want to preserve the Attribute elements, remove the line below -->
            <xsl:apply-templates select="node()"/>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.