0

I have :

<ExtData>
<table>
    <Column biz="Bus" desc="" id="Bus" >
        <CoreColumn coreEntityName="ser" coreId="Bus" coreColumnDataType="TypeInt" coreColumnLength=""/>
    </Column>
    <Column biz="ser" desc="" id="NAME" >
        <CoreColumn coreEntityName="ser" coreId="NAME" coreColumnDataType="TypeVarChar" />
    </Column>
    <Column biz="ID" desc=""  id="GLOBAL_ID" >
        <CoreColumn coreEntityName="ser" coreId="UCMDB_ID" coreColumnDataType="VarChar" />
        <CoreColumn coreEntityName="ser_xxx" coreId="UCMDB_ID" coreColumnDataType="VarChar" />
    </Column>
    <Column biz="State" desc="" id="ser_STATE" >
        <CoreColumn coreEntityName="ser" coreId="ser_STATE" coreColumnDataType="VarChar" />
    </Column>
</table>

and need output >>> filtered by atribute @coreEntityName="ser" :

<ExtData>
<table>
    <Column biz="Bus" desc="" id="Bus" >
        <CoreColumn coreEntityName="ser" coreId="Bus" coreColumnDataType="TypeInt" coreColumnLength=""/>
    </Column>
    <Column biz="ser" desc="" id="NAME" >
        <CoreColumn coreEntityName="ser" coreId="NAME" coreColumnDataType="TypeVarChar" />
    </Column>
    <Column biz="ID" desc=""  id="GLOBAL_ID" >
        <CoreColumn coreEntityName="ser" coreId="UCMDB_ID" coreColumnDataType="VarChar" />
    </Column>
    <Column biz="State" desc="" id="ser_STATE" >
        <CoreColumn coreEntityName="ser" coreId="ser_STATE" coreColumnDataType="VarChar" />
    </Column>
</table>

1
  • What does your XSL look like, and what is the issue with the transformation? Commented Feb 26, 2013 at 13:54

1 Answer 1

3

The following XSLT stylesheet achieve the desired output:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>

    <!-- Identity template : copy attributes and elements by default -->
    <xsl:template match="@*|*">
        <xsl:copy>
            <xsl:apply-templates select="@*|*" />
        </xsl:copy>
    </xsl:template>

    <!-- Exclude all the CoreColumn elements such as their @coreEntityname
         attribute is other than ser -->
    <xsl:template match="CoreColumn[@coreEntityName != 'ser']" />

</xsl:stylesheet>
Sign up to request clarification or add additional context in comments.

3 Comments

Hi Pablo. it's work, but why match="CoreColumn[@coreEntityName != 'ser']" (not equal) and not match="CoreColumn[@coreEntityName = 'ser']" (equal)
In the solution I am using the identity template, which copies by default all the elements and attributes in the XML document. So, every CoreColumn is going to be copied. What we need to do is to exclude all the CoreColumns such as @coreEntityName is different than 'ser', so we use an empty template to avoid processing those elements: <xsl:template match="CoreColumn[@coreEntityName != 'ser']" />. That template could be read as: for each CoreColumn element with a coreEntityName attribute different than 'ser', do nothing (i.e. exclude it).
nicely explained Pablo.. +1

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.