|
next
|
 Subject: Prublem in XSLT Author: misha tsvet Date: 04 Aug 2006 04:35 PM Originally Posted: 04 Aug 2006 04:30 PM
|
i have such input.
<records>
<record>
<ADDED_XML>motorola_Norway.xml</ADDED_XML>
<ADDED_MANUF>Motorola<ADDED_MANUF>
<ADDED_NAME>gidra</ADDED_NAME>
<ADDED_URL>http://direct.motorola.com/nrn/phoneselect.asp?country=NRW&amp;language=NRN&amp;productid=30385&amp;web_page_name=OTHERPHONE</ADDED_URL>
<REMOVED_MANUF>Motorola</REMOVED_MANUF>
<REMOVED_NAME>L2</REMOVED_NAME>
<REMOVED_URL>http://direct.motorola.com/nrn/phoneselect.asp?country=NRW&amp;language=NRN&amp;productid=30385&amp;web_page_name=OTHERPHONE
</REMOVED_URL>
</record>
<record>
<ADDED_XML>motorola_Norway.xml</ADDED_XML>
<ADDED_MANUF>Motorola</ADDED_MANUF>
<ADDED_NAME>L226</ADDED_NAME>
<ADDED_URL>http://direct.motorola.com/nrn/phoneselect.asp?country=NRW&amp;language=NRN&amp;productid=30385&amp;web_page_name=OTHERPHONE
</ADDED_URL>
<REMOVED_MANUF>Motorola</REMOVED_MANUF>
<REMOVED_NAME>L2</REMOVED_NAME>
<REMOVED_URL>http://direct.motorola.com/nrn/phoneselect.asp?country=NRW&amp;language=NRN&amp;productid=30385&amp;web_page_name=OTHERPHONE
</REMOVED_URL>
</record>
I need to get such stucture:
<changes file="1.xml">
<added>
<device name="1" src-url="2"/>
<device name="3" src-url="4"/>
</added>
<removed>
<device name="5" src-url="6"/>
<device name="7" src-url="8"/>
</removed
</changes>
<changes file="2.xml">
<added>
<device name="12" src-url="23"/>
<device name="34" src-url="45"/>
</added>
<removed>
<device name="56" src-url="67"/>
<device name="78" src-url="89"/>
</removed
</changes>
I write such sctipt:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="records" match="records/record" use="concat(ADDED_XML,ADDED_MANUF, ADDED_NAME,ADDED_URL,REMOVED_MANUF,REMOVED_NAME,REMOVED_URL)"/>
<xsl:template match="/">
<device-diff>
<xsl:for-each select="/records/record[generate-id() = generate-id(key('records', concat(ADDED_XML,ADDED_MANUF, ADDED_NAME,ADDED_URL,REMOVED_MANUF,REMOVED_NAME,REMOVED_URL))[1])]">
<changes file="{ADDED_XML}">
<added>
<xsl:variable name="keyVal" select="concat(ADDED_XML,ADDED_MANUF, ADDED_NAME,ADDED_URL,REMOVED_MANUF,REMOVED_NAME,REMOVED_URL)"/>
<xsl:for-each select="/records/record[concat(ADDED_XML,ADDED_MANUF, ADDED_NAME,ADDED_URL,REMOVED_MANUF,REMOVED_NAME,REMOVED_URL) = $keyVal]">
<device manufacturer="{ADDED_MANUF}" name="{ADDED_NAME}" src-url="{ADDED_URL}"/>
</xsl:for-each>
</added>
<removed>
<xsl:variable name="keyVal" select="concat(ADDED_XML,ADDED_MANUF, ADDED_NAME,ADDED_URL,REMOVED_MANUF,REMOVED_NAME,REMOVED_URL)"/>
<xsl:for-each select="/records/record[concat(ADDED_XML,ADDED_MANUF, ADDED_NAME,ADDED_URL,REMOVED_MANUF,REMOVED_NAME,REMOVED_URL) = $keyVal]">
<device manufacturer="{REMOVED_MANUF}" name="{REMOVED_NAME}" src-url="{REMOVED_URL}"/>
</xsl:for-each>
</removed>
</changes>
</xsl:for-each>
</device-diff>
</xsl:template>
</xsl:stylesheet>
But i get :
<changes file="motorola_Norway.xml">
<added>
<device manufacturer="Motorola" name="gidra" src-url="http://direct.motorola.com/nrn/phoneselect.asp?country=NRW&amp;language=NRN&amp;productid=30385&amp;web_page_name=OTHERPHONE"/>
</added>
<removed>
<device manufacturer="Motorola" name="L2" src-url="http://direct.motorola.com/nrn/phoneselect.asp?country=NRW&amp;language=NRN&amp;productid=30385&amp;web_page_name=OTHERPHONE"/>
</removed>
</changes>
<changes file="motorola_Norway.xml">
<added>
<device manufacturer="Motorola" name="L226" src-url="http://direct.motorola.com/nrn/phoneselect.asp?country=NRW&amp;language=NRN&amp;productid=30385&amp;web_page_name=OTHERPHONE"/>
</added>
<removed>
<device manufacturer="Motorola" name="L2" src-url="http://direct.motorola.com/nrn/phoneselect.asp?country=NRW&amp;language=NRN&amp;productid=30385&amp;web_page_name=OTHERPHONE"/>
</removed>
</changes>
PLz help me.
|
|
|
|