0

Can anyone please help in wring XSLT for this, I want to substring value of one attribute "UDF/@Value" to first 20 characters and I want to substring all UDF/@Value .

Input XML:

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Header FileDate="02/12/2015" InputDateFormat="MM/dd/yyyy"/>
  <Body DataType="Account">
<Account  Name="XYZ"  InceptionDate="03/01/2005"  DEPT="USD BU" BusinessUnit="WTC" ClientAccountId="123" ISOCurrency="USD" >
<UDF Name="Product" Value="DUMMY"/>
<UDF Name="QUANTITY" Value="abc def ghi jkl mno pqr stu vwz yz"/>
</Account>
<Account  Name="ABC"  InceptionDate="03/01/2005"  DEPT="USD BU" BusinessUnit="WTC" ClientAccountId="124" ISOCurrency="USD" >
<UDF Name="Comment" Value="abc 10percent and 20 and at xyz"/>
<UDF Name="Product Code" Value="EMMKTOPP"/>
</Account>
</Body>
  <Trailer RecordCount="2"/>
</root>

Output xml :

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Header FileDate="02/12/2015" InputDateFormat="MM/dd/yyyy"/>
  <Body DataType="Account">
<Account  Name="XYZ"  InceptionDate="03/01/2005"  DEPT="USD BU" BusinessUnit="WTC" ClientAccountId="123" ISOCurrency="USD" >
<UDF Name="Product" Value="DUMMY"/>
<UDF Name="QUANTITY" Value="abc def ghi jkl mno "/>
</Account>
<Account  Name="ABC"  InceptionDate="03/01/2005"  DEPT="USD BU" BusinessUnit="WTC" ClientAccountId="124" ISOCurrency="USD" >
<UDF Name="Comment" Value="abc 10percent and 20"/>
<UDF Name="Product Code" Value="EMMKTOPP"/>
</Account>
</Body>
  <Trailer RecordCount="2"/>
</root>
1
  • What do you mean by "I want to substring all UDF/@Value“? Commented Mar 3, 2015 at 3:08

1 Answer 1

2

You can use an identity template to copy all nodes:

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

And a specific template to deal with the UDF element, applying substring only on the Value attribute:

<xsl:template match="UDF">
    <UDF Value="{substring(@Value, 0, 20)}" Name="{@Name}"/>
</xsl:template>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot helderdarocha

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.