473,654 Members | 3,062 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
<groupCustomBuc ketList> list has an entry in each of the
<groupCustomBuc ket> 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>EST OXX50 INDEX_BM_E</positionId>
</equity>
<equity>
<positionId>FTS E INDEX_BM_E</positionId>
</equity>

<groupCustomBuc ketList>
<groupCustomBuc ket>
<customDimensio nName>Branch</customDimension Name>
<customBucketVa lue>BENCHMARK</customBucketVal ue>
<positionIdList >
<positionId>B MK ZENIT ESTOXX50 INDEX_BM_E</positionId>
<positionId>B MK ZENIT FTSE INDEX_BM_E</positionId>
</positionIdList>
</groupCustomBuck et>
<groupCustomBuc ket>
<customDimensio nName>Folder</customDimension Name>
<customBucketVa lue>BZ_ESTOX50</customBucketVal ue>
<positionIdList >
<positionId>B MK ZENIT ESTOXX50 INDEX_BM_E</positionId>
</positionIdList>
</groupCustomBuck et>
<groupCustomBuc ket>
<customDimensio nName>Folder</customDimension Name>
<customBucketVa lue>BZ_FTSE</customBucketVal ue>
<positionIdList >
<positionId>B MK ZENIT FTSE INDEX_BM_E</positionId>
</positionIdList>
</groupCustomBuck et>
<groupCustomBuc ket>
<customDimensio nName>Portfolio </customDimension Name>
<customBucketVa lue>BMK_ZENIT</customBucketVal ue>
<positionIdList >
<positionId>B MK ZENIT ESTOXX50 INDEX_BM_E</positionId>
<positionId>B MK ZENIT FTSE INDEX_BM_E</positionId>
</positionIdList>
</groupCustomBuck et>
<groupCustomBuc ket>
<customDimensio nName>CurrencyR egion</customDimension Name>
<customBucketVa lue>EUR</customBucketVal ue>
<positionIdList >
<positionId>B MK ZENIT ESTOXX50 INDEX_BM_E</positionId>
</positionIdList>
</groupCustomBuck et>
</groupCustomBuck etList>
</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:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">

<xsl:variable
name="tagstosca n">Branch,Portf olio,Folder,Cur rencyRegion,</xsl:variable>

<xsl:template match="/">
<xsl:element name="positions ">
<xsl:attribut e name="nbofcolum ns">
<xsl:call-template name="count_nb_ of_tags">
<xsl:with-param name="tags"><xs l:value-of select="$tagsto scan"
/></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"><xs l:value-of select="$tagsto scan"
/></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="substri ng-before($tags, ',')" />
<xsl:param name="count" />

<xsl:if test="string-length($tag) = 0"><xsl:valu e-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="substri ng-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="substri ng-before($tags, ',')" />

<xsl:if test="string-length($tag) > 0">
<xsl:element name="position" >
<xsl:attribut e name="positionI d"></xsl:attribute>
<xsl:call-template name="loop_posi tion">
<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="substri ng-after($tags, ',')" />
</xsl:call-template>
</xsl:if>
</xsl:template>

<!-- Tag parsing -->
<xsl:template name="loop_tag" >
<xsl:param name="tags" />
<xsl:for-each select="positio ns/*/positionId">
<xsl:call-template name="find_id_i n_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_i n_taglist">
<xsl:param name="id" />
<xsl:param name="tag" />
<xsl:if
test="string-length(/positions/groupCustomBuck etList/groupCustomBuck et/customDimension Name[.
= $tag]/../positionIdList/positionId[. = $id]) = 0">

<xsl:attribut e name="positionI d"><xsl:valu e-of select="$id"
/></xsl:attribute>
<xsl:variable name="fixedid"> <xsl:call-template
name="remove_sp ace"><xsl:with-param name="string" select="$tag"
/></xsl:call-template></xsl:variable>
<xsl:attribut e name="{$fixedid }">1</xsl:attribute>
</xsl:if>
</xsl:template>

<!-- Position parsing -->
<xsl:template name="loop_posi tion">
<xsl:param name="tags" />
<xsl:for-each
select="/positions/groupCustomBuck etList/groupCustomBuck et/customDimension Name[.
= $tags]/../positionIdList/positionId">
<xsl:call-template name="find_id_i n_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_i n_positionlist" >
<xsl:param name="id" />
<xsl:param name="tag" />
<xsl:if test="string-length(/positions/*/positionId[. = $id]) = 0">
<xsl:attribut e name="positionI d"><xsl:valu e-of select="$id"
/></xsl:attribute>
<xsl:variable name="fixedid"> <xsl:call-template
name="remove_sp ace"><xsl:with-param name="string" select="$tag"
/></xsl:call-template></xsl:variable>
<xsl:attribut e name="{$fixedid }">1</xsl:attribute>
</xsl:if>
</xsl:template>

<!-- Remove spaces -->
<xsl:template name="remove_sp ace">
<xsl:param name="string" />
<xsl:choose>
<xsl:when test="contains( $string, ' ')">
<xsl:call-template name="remove_sp ace">
<xsl:with-param name="string">
<xsl:value-of select="substri ng-before($string, ' ')"
/><xsl:value-of select="substri ng-after($string, ' ')" />
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwis e>
<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="processi ng-instruction()|c omment()" >
<!-- 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 1713
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
2434
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 I'm at a complete loss as to what is wrong with the one below. This is a very abbreviated server-config.wsdd: <?xml version="1.0" encoding="UTF-8"?> <deployment xmlns="http://xml.apache.org/axis/wsdd/"...
7
3242
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 the XML, and then run the XSL transformation on it using the MSXML2.IXSLProcessor interface. The problem is that it kills my system because of an incredible amount of memory that it requires to do this (around 850 MB). Are there any other...
8
2364
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. <car><make>ford</make><color>red</color><year>2001</year></car><car><make><mb> etc. etc. etc. Some lines are over 300 characters long. I need to translate this spagetti XML into something which is humanly readable. I probably need to use XSL however I'm not sure...
4
4725
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 immediately followed by the input node text values in one long string -- no xml tags (barring the xml declaration, of course) appear in the output file. Anyone who wants to see either the input xml file or the xsl file, please let me know and I will...
5
7381
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 store and render web content. Reason being that we are considering migrating our website content to XML and using XSLT to transform the content into html. Currently lack of browser support for XSLT has held us back. For example a significant...
2
1785
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 XmlSpy and in output window I can see two parallel elements - according to "logic" of me sheet. The error of that document is that it doesn't have root element. Here is the contents of XmlSpy output window:
3
1255
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 for me,because I need to frequently callback the server.Is there any solution to reduce the data? thanks
4
1515
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 same way it would if i were just putting it in a regular php file? how i can do this? oh and made this <?php $hello="<?php echo 'hello my name is sam';
1
1794
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 and would like to ask here for some advice. I want to have a class DataSet which holds the data to be transformed; I want to have a class Transformation which transform a DataSet object into another DataSet object. For the long-term,...
0
8375
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8290
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8482
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8593
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7306
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2714
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1593
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.