xml - XSLT task: replicate a list of element for each element of a different list with exceptions -
xml - XSLT task: replicate a list of element for each element of a different list with exceptions -
i have problem trying setup template solve address situation:
my xml looks like:
<root> <recordset name="companies"> <record> <id>1</id> <description>company 1</description> </record> <record><id>2</id><description>company 2</description></record> ... <record><id>n</id><description>company n</description></record> </recordset> <gruppi> <supplier> <agreement>1</agreement> <company> <id>3</id> <description>compoany 3</description> </company> <company> <id>7</id> <description>company 7</description> </company> </supplier> ... <!-- lot of supplier --> ... <supplier> <agreement>3</agreement> <company> <id>1</id> <description>company 1</description> </company> <company> <id>18</id> <description>company 18</description> </company> </supplier> </gruppi> </root>
my aim have template able perform next processing: each supplier within gruppi wish output list of record within recordset name="companies" except record id contained in id element descendent of current supplier element.
in other words: each supplier should create set of html options listing companies (id values) not including companies included in supplier
i tried utilize xsl:key , recursion found task quite involved , running out of ideas. has hint solve problem?
thanks help!
@polishchuk: xml input quite big file, extracted construction interested in filling few generic data. output looking this:
<h1>agreement: 1</h1> <select> <option value="1"></option> .... <!-- without values 3 , 7 --> <option value="n"></option> </select> <h1>agreement: 3</h1> <select> <option value="1"></option> .... <!-- without values 1 , 18 --> <option value="n"></option> </select>
xslt:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" > <xsl:output method="xml" indent="yes"/> <xsl:template match="/"> <xsl:apply-templates select="//supplier"/> </xsl:template> <xsl:template match="supplier"> <h1> <xsl:text>agreement: </xsl:text> <xsl:value-of select="agreement"/> </h1> <select> <xsl:for-each select="//recordset[@name = 'companies']/record[not(id = current()/company/id)]"> <option value="{id}"> <xsl:value-of select="id"/> </option> </xsl:for-each> </select> </xsl:template> </xsl:stylesheet>
supposed xml:
<root> <recordset name="companies"> <record> <id>1</id> <description>company1</description> </record> <record> <id>2</id> <description>company2</description> </record> <record> <id>3</id> <description>company3</description> </record> <record> <id>4</id> <description>company4</description> </record> <record> <id>5</id> <description>company5</description> </record> </recordset> <gruppi> <supplier> <agreement>1</agreement> <company> <id>1</id> </company> <company> <id>2</id> </company> </supplier> <supplier> <agreement>2</agreement> <company> <id>1</id> </company> <company> <id>3</id> </company> </supplier> <supplier> <agreement>3</agreement> <company> <id>4</id> </company> <company> <id>5</id> </company> </supplier> </gruppi> </root>
output:
<h1>agreement: 1</h1> <select> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> <h1>agreement: 2</h1> <select> <option value="2">2</option> <option value="4">4</option> <option value="5">5</option> </select> <h1>agreement: 3</h1> <select> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select>
xml xslt xpath
Comments
Post a Comment