473,412 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Need help remake xsl transformation

Hi everyone
From one of our systems an xml file is produced. I need to validate

this file before we send it to an external system for a very lenghty
process. I cannot change the xml file layout.
The solution i got today is very slow, and i need help to find another
solution.

Here is the xml file. It consists of a list of position ids (ESTOXX50
INDEX_BM_E and FTSE INDEX_BM_E), and below that a list of tags for each
position id. What i want to do is see that each entry not being in the
<groupCustomBucketList> list has an entry in each of the
<groupCustomBucket> tags below. And vice versa; that each position id
from each tag exists in the list of <equity>. See xsl transformation
below.

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="t.xsl"?>
<positions>
<equity>
<positionId>ESTOXX50 INDEX_BM_E</positionId>
</equity>
<equity>
<positionId>FTSE INDEX_BM_E</positionId>
</equity>

<groupCustomBucketList>
<groupCustomBucket>
<customDimensionName>Branch</customDimensionName>
<customBucketValue>BENCHMARK</customBucketValue>
<positionIdList>
<positionId>BMK ZENIT ESTOXX50 INDEX_BM_E</positionId>
<positionId>BMK ZENIT FTSE INDEX_BM_E</positionId>
</positionIdList>
</groupCustomBucket>
<groupCustomBucket>
<customDimensionName>Folder</customDimensionName>
<customBucketValue>BZ_ESTOX50</customBucketValue>
<positionIdList>
<positionId>BMK ZENIT ESTOXX50 INDEX_BM_E</positionId>
</positionIdList>
</groupCustomBucket>
<groupCustomBucket>
<customDimensionName>Folder</customDimensionName>
<customBucketValue>BZ_FTSE</customBucketValue>
<positionIdList>
<positionId>BMK ZENIT FTSE INDEX_BM_E</positionId>
</positionIdList>
</groupCustomBucket>
<groupCustomBucket>
<customDimensionName>Portfolio</customDimensionName>
<customBucketValue>BMK_ZENIT</customBucketValue>
<positionIdList>
<positionId>BMK ZENIT ESTOXX50 INDEX_BM_E</positionId>
<positionId>BMK ZENIT FTSE INDEX_BM_E</positionId>
</positionIdList>
</groupCustomBucket>
<groupCustomBucket>
<customDimensionName>CurrencyRegion</customDimensionName>
<customBucketValue>EUR</customBucketValue>
<positionIdList>
<positionId>BMK ZENIT ESTOXX50 INDEX_BM_E</positionId>
</positionIdList>
</groupCustomBucket>
</groupCustomBucketList>
</positions>

-----------------
Here is the xsl file. What i use is loads of call-template executes
which i guess is the performance issue. The code below works, but it's
really messy. And slow.
I have two "functions" loop_position and loop_tag that validates each
tag type against the position ids.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:variable
name="tagstoscan">Branch,Portfolio,Folder,Currency Region,</xsl:variable>

<xsl:template match="/">
<xsl:element name="positions">
<xsl:attribute name="nbofcolumns">
<xsl:call-template name="count_nb_of_tags">
<xsl:with-param name="tags"><xsl:value-of select="$tagstoscan"
/></xsl:with-param>
<xsl:with-param name="count">0</xsl:with-param>
</xsl:call-template>
</xsl:attribute>
<!-- Find tags that are illegal -->
<xsl:call-template name="loop">
<xsl:with-param name="tags"><xsl:value-of select="$tagstoscan"
/></xsl:with-param>
</xsl:call-template>
</xsl:element>
</xsl:template>

<!-- Count the number of tags we are processing -->
<xsl:template name="count_nb_of_tags">
<xsl:param name="tags" />
<xsl:param name="tag" select="substring-before($tags, ',')" />
<xsl:param name="count" />

<xsl:if test="string-length($tag) = 0"><xsl:value-of select="$count"
/> </xsl:if>

<xsl:if test="string-length($tags) > 0">
<xsl:call-template name="count_nb_of_tags">
<xsl:with-param name="tags" select="substring-after($tags, ',')" />
<xsl:with-param name="count" select="$count + 1" />
</xsl:call-template>
</xsl:if>
</xsl:template>

<!-- Loop all tags we are processing, parsing the xml. Check two
directions: positions to tags, and reverse -->
<xsl:template name="loop">
<xsl:param name="tags" />
<xsl:param name="tag" select="substring-before($tags, ',')" />

<xsl:if test="string-length($tag) > 0">
<xsl:element name="position">
<xsl:attribute name="positionId"></xsl:attribute>
<xsl:call-template name="loop_position">
<xsl:with-param name="tags" select="$tag" />
</xsl:call-template>
<xsl:call-template name="loop_tag">
<xsl:with-param name="tags" select="$tag" />
</xsl:call-template>
</xsl:element>
</xsl:if>

<xsl:if test="string-length($tags) > 0">
<xsl:call-template name="loop">
<xsl:with-param name="tags" select="substring-after($tags, ',')" />
</xsl:call-template>
</xsl:if>
</xsl:template>

<!-- Tag parsing -->
<xsl:template name="loop_tag">
<xsl:param name="tags" />
<xsl:for-each select="positions/*/positionId">
<xsl:call-template name="find_id_in_taglist">
<xsl:with-param name="id" select="." />
<xsl:with-param name="tag" select="$tags" />
</xsl:call-template>
</xsl:for-each>
</xsl:template>

<xsl:template name="find_id_in_taglist">
<xsl:param name="id" />
<xsl:param name="tag" />
<xsl:if
test="string-length(/positions/groupCustomBucketList/groupCustomBucket/customDimensionName[.
= $tag]/../positionIdList/positionId[. = $id]) = 0">

<xsl:attribute name="positionId"><xsl:value-of select="$id"
/></xsl:attribute>
<xsl:variable name="fixedid"><xsl:call-template
name="remove_space"><xsl:with-param name="string" select="$tag"
/></xsl:call-template></xsl:variable>
<xsl:attribute name="{$fixedid}">1</xsl:attribute>
</xsl:if>
</xsl:template>

<!-- Position parsing -->
<xsl:template name="loop_position">
<xsl:param name="tags" />
<xsl:for-each
select="/positions/groupCustomBucketList/groupCustomBucket/customDimensionName[.
= $tags]/../positionIdList/positionId">
<xsl:call-template name="find_id_in_positionlist">
<xsl:with-param name="id" select="." />
<xsl:with-param name="tag" select="$tags" />
</xsl:call-template>
</xsl:for-each>
</xsl:template>

<xsl:template name="find_id_in_positionlist">
<xsl:param name="id" />
<xsl:param name="tag" />
<xsl:if test="string-length(/positions/*/positionId[. = $id]) = 0">
<xsl:attribute name="positionId"><xsl:value-of select="$id"
/></xsl:attribute>
<xsl:variable name="fixedid"><xsl:call-template
name="remove_space"><xsl:with-param name="string" select="$tag"
/></xsl:call-template></xsl:variable>
<xsl:attribute name="{$fixedid}">1</xsl:attribute>
</xsl:if>
</xsl:template>

<!-- Remove spaces -->
<xsl:template name="remove_space">
<xsl:param name="string" />
<xsl:choose>
<xsl:when test="contains($string, ' ')">
<xsl:call-template name="remove_space">
<xsl:with-param name="string">
<xsl:value-of select="substring-before($string, ' ')"
/><xsl:value-of select="substring-after($string, ' ')" />
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<!-- Override default template rules -->

<xsl:template match="*|/" mode="m">
<!-- Do nothing. Override default rule -->
</xsl:template>

<xsl:template match="processing-instruction()|comment()" >
<!-- Do nothing. Override default rule -->
</xsl:template>

<xsl:template match="text() | @*">
<!-- Do nothing. Override default rule -->
</xsl:template>

</xsl:stylesheet>
Regards,
/Johan

Jun 19 '06 #1
1 1698
Convolving sets against each other is expensive. Try recasting the problem.

For example: your second constraint is that the union of the two index
lists is precisely equal to the list of entries, after duplicates are
eliminated. That can be computed by collecting the sets, sorting them,
ensuring no dupes exist, and then doing a comparison of the result. That
may be faster (especially if you know a priori that some of these
subsets are already sorted.)

Establishing that the intersection of the two index sets is empty,
similarly, might be run faster if you test it by establishing that the
length of the sorted-unique union of the two is equal to the sum of the
sorted-unique lengths of each index set.

But I suspect the fastest way to do this particular set of tests would
be to drop down to a lower level and handle it in SAX or DOM, building
hashtables or similar content-addressable retrieval mechanisms. The fact
that XSLT is a complete programming language for manipulating XML
doesn't necessarily mean it's the optimal one for all tasks.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Jun 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Kevin Dean | last post by:
I'm trying to create an XSL transformation that will strip out development-specific attributes from deployment descriptors and other XML files. I have already successfully done so with web.xml but...
7
by: CK | last post by:
Hello, I have the 60 MB XML string and I am coding a program in Visual Basic to run a XSL transformation on it. Currently, I'm using the Microsoft standard MSXML 2.0 to create a DOM document, load...
8
by: Will | last post by:
I was thrust into XML about 2 weeks ago and don't know much yet. From another department in the corp I am receiving an XML file which concatenates nodes all on one line i.e....
4
by: Mike Conmackie | last post by:
Hi Folks, I've probably omitted something very basic but I have no idea what it might be. The results of my transformation _should_ be an xml file but all I get is the xml declaration...
5
by: Mike Judkins | last post by:
I'm looking for examples of websites (preferably large and well known companies, not personal sites or developer-to-developer sites) that use XML and XSLT as a technology platform from which to...
2
by: TomekR | last post by:
Hello ! I was developing xslt sheet lately and - experimenting - I made mistake resulting in that, the effect of the transformation is not well-formed xml document. I made these tests using...
3
by: atzhuqj | last post by:
These days I'm working with a web project.I use asp.net 2.0 callBack to refresh the web page without postback,but I found the client have to send a lot of data to server,that is not so EFFICIENT...
4
by: funkychicken818 | last post by:
hello i am going to remake my site and well i want to place all my code in a database were i can access the code and output, just how can i make it so when i access this code it outputs exactly the...
1
by: newbie | last post by:
This is probably a too general question, thanks for any feedback in advance. I am trying to write a class to do transformation on a data set. I want to make it easy to maintain in the long-run...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.