|
Subject: Selecting (and excluding) nodes From: Marcus Andersson <marcus@xxxxxxxxxx> Date: Tue, 22 Jun 2004 16:55:58 +0200 |
<docroot>
<services>
<service id="842" name="service1"/>
<service id="843" name="service2"/>
<service id="844" name="service3"/>
<service id="845" name="service4"/>
</services> <categories>
<section>
<category name="cat1">
<service ref="842"/>
<service ref="844"/>
</category>
<category name="cat2">
<service ref="842"/>
<service ref="843"/>
<service ref="845"/>
</category>
<category name="cat3">
<service ref="843"/>
</category>
</section>
</categories> <node>
<node>
<services>
<service ref="842"/>
<service ref="844"/>
<service ref="845"/>
</services>
<node>
<ipranges>
<range from="111111111111" to="222222222222"/>
<range from="333333333333" to="444444444444"/>
</ipranges>
<services>
<service ref="843"/>
</service>
</node>
</node>
</nodes>
</docroot><result>
<items>
<item id="842" name="service1"/>
<item id="843" name="service2"/>
<item id="844" name="service3"/>
<item id="845" name="service4"/>
</items> <categories>
<category name="cat1">
<item ref="842"/>
<item ref="844"/>
</category>
<category name="cat2">
<item ref="842"/>
<item ref="845"/>
</category>
</categories>
</result><?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<!-- The following three variables might replacable by just one.
I haven't figured out how though.
It's only $selectedNode that is interesting --> <xsl:variable name="selectedNodeByIp"
select="/docroot/nodes//node[ipranges/range[number(@from) <= $ip and $ip <= number(@to)]][1]"/> <xsl:variable name="selectedNodeId">
<xsl:choose>
<xsl:when test="$selectedNodeByIp"><xsl:value-of select="$selectedNodeByIp/@id"/></xsl:when>
<xsl:otherwise><xsl:value-of select="/docroot/nodes/node[1]/@id"/></xsl:otherwise>
</xsl:choose>
</xsl:variable> <xsl:template match="/docroot">
<docroot>
<items>
<xsl:for-each select="$selectedServices">
<item>
<xsl:copy-of select="@*"/>
</item>
</xsl:for-each>
</items>
<categories>
<xsl:apply-templates select="categories/section/category"/>
</categories>
</docroot>
</xsl:template> <xsl:template match="category">
<xsl:variable name="acat">
<category>
<xsl:copy-of select="@*"/>
<xsl:for-each select="service">
<xsl:if test="$selectedServices[@ref=current()/@ref]">
<item ref="{@ref}"/>
</xsl:if>
</xsl:for-each>
</category>
</xsl:variable>
<xsl:variable name="cat" select="msxsl:node-set($acat)/category"/>
<xsl:if test="count($cat/*) > 0">
<xsl:copy-of select="$cat"/>
</xsl:if>
</xsl:template>| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] List of Unique Items with, Michael Kay | Thread | [xsl] conversion from xslt2.0 to xs, TDarksword |
| List of Unique Items within an XML , Ben Gazzard | Date | RE: [xsl] List of Unique Items with, Kenny Akridge |
| Month |