Avoid doing double calculations in XSL



I'm working on a XSLT transformation. I'm fairly new to XSLT, and I'm having some trouble with it to put it mildly. I'm working on some input, and based on some calculations (checking intersections on polygons, which takes extensive amounts of time, since the data amount is huge), I want to add some elements to a collection.


At the end of the output I want to have an indicator stating whether or not that list contains elements - really simple, but still having trouble. I found out that it's not possible to access the preliminary generated data inside the transformation, since apparently only the input is available.


this is my input. Note that this input can be repeated several times, so the transformation iterates over all the "IterationResponses".



<IterationResponse Iteration="0">
<QueryResult>
<Collection>
<Element>
<Name>City1</Name>
<number>151</number>
<Link>Link1</Link>
<GMLData>[massive data amount]</GMLData>
</Element>
<Element>
<Name>City1</Name>
<number>151</number>
<Link>Link2</Link>
<GMLData>[massive data amount]</GMLData>
</Element>
<Element>
<Name>City2</Name>
<number>190</number>
<Link>Link3</Link>
<GMLData>[massive data amount]</GMLData>
</Element>
<Element>
<Name>City3</Name>
<number>163</number>
<Link>Link4</Link>
<GMLData>[massive data amount]</GMLData>
</Element>
</Collection>
</QueryResult>
<Selection>
<cadastral>
<cadastralPolygon>
<Polygon>
<exterior>
<LinearRing>
<posList>[small amount of data]</posList>
</LinearRing>
</exterior>
</Polygon>
</cadastralPolygon>
</cadastral>
</Selection>
</IterationResponse>


And this is the transformation I currently have (simplified alot since the actual input, transformation and output is huge, but the issue remains)



<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://ift.tt/tCZ8VR"
xmlns:soapenv="http://ift.tt/sVJIaE"
xmlns:xsi="http://ift.tt/ra1lAU"
xmlns:xsd="http://ift.tt/tphNwY"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="var_bufferWidth" select="'-0.5'" />

<QueryResult>
<xsl:choose>
<xsl:when test="count(//Error) >= 1">
<!-- Error handling -->
</xsl:when>
<xsl:otherwise>
<Overview>
<OverviewCollection>
<!--Iterate all iteration responses-->
<xsl:for-each select="//IterationResponse">
<xsl:variable name="cadastralGML" select="Selection/cadastral/cadastralPolygon"/>
<xsl:for-each select=".//OverviewElement">
<xsl:if test="func:Conflicts($cadastralGML, GMLData, $var_bufferWidth)">
<OverviewElement>
<Number>
<xsl:value-of select="concat('0',Kommunenummer)"/>
<Number>
<Name>
<xsl:value-of select="Kommunenavn"/>
</Name>
<Reference>
<xsl:value-of select="Link"/>
<Reference>
</OverviewElement>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
<OverviewCollection>
<OverviewIndicator>
<xsl:value-of select="count(/*//OverviewElement) > 0"/>
<OverviewIndicator>
</Overview>
</xsl:otherwise>
</xsl:choose>
</QueryResult>
</xsl:template>


This is my current output.



<Overview>
<OverviewCollection>
<OverviewElement>
<Number>0151</Number>
<Name>City1</Name>
<Reference>Link1<Reference>
</OverviewElement>
</OverviewCollection>
<OverviewIndicator>false</OverviewIndicator>
</Overview>


Instead of false i want it to be true, since the final collection is not empty. Any help is greatly appreciated!


Thanks in advance.


No comments:

Post a Comment