Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: include document and concatanated id's [Thread Next] Re: include document and concatanated id'sTo: NULL Date: 4/8/2008 5:05:00 PM
Damn. I've found out that some documents contain a ref attribute rather
than an id and that some contain both.
So given
------ component.xml -----
<component>
<parts id='main' url='assembly.data' />
</component>
--------------------------
and
------ assembly.data -----
<assembly id='outerBox' width='400'>
<name'>Cardboard Outer</name>
<price id='outerPrice' value='200' />
</assembly>
<assembly ref='oldBox' width='400'>
<name'>Ancient Cardboard</name>
<price id='oldPrice' value='200' />
</assembly>
<assembly id='fossil' width='400'>
<name'>Fossilized Cardboard</name>
<price ref='fossilPrice' value='200' />
</assembly>
<assembly id='wierdBox' width='400'>
<name'>Wierd Cardboard</name>
<price id='wierdPrice' ref='originalWierdPrice' value='200' />
</assembly>
--------------------------------
----- result -----
<component>
<assembly id='main$outerBox' width='400'>
<name'>Cardboard Outer</name>
<price id='main$outerPrice' value='200' />
</assembly>
<assembly ref='main$oldBox' width='400'>
<name'>Ancient Cardboard</name>
<price id='main$oldPrice' value='200' />
</assembly>
<assembly id='main$fossil' width='400'>
<name'>Fossilized Cardboard</name>
<price ref='main$fossilPrice' value='200' />
</assembly>
<assembly id='main$wierdBox' width='400'>
<name'>Wierd Cardboard</name>
<price id='main$wierdPrice' ref='main$originalWierdPrice'
value='200' />
</assembly>
</component>
------------------
Is this possible?
Martin
Martin Honnen wrote:
> Martin wrote:
>
>> I need to change this xsl to combine id's (if present) so i get:
>>
>> ----- result -----
>> <component id='mainProduct'>
> ^^^^^^^^^^^^^^^
>
> It is not clear where that id comes from.
>
>> <assembly id='main$outerBox' width='400'>
>> <name'>Cardboard Outer</name>
>> <price id='main$outerPrice' value='200' />
>> </assembly>
>> </component>
>
> Here is an XSLT 1.0 stylesheet processing the nodes to be changed in a
> different mode and passing in the "prefix" as a parameter:
>
> <xsl:stylesheet
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
>
> <xsl:output method="xml"/>
>
> <xsl:template match="component">
> <xsl:copy>
> <xsl:apply-templates/>
> </xsl:copy>
> </xsl:template>
>
> <xsl:template match="parts">
> <xsl:apply-templates select="document(@url)/*" mode="fix">
> <xsl:with-param name="prefix" select="@id"/>
> </xsl:apply-templates>
> </xsl:template>
>
> <xsl:template match="*" mode="fix">
> <xsl:param name="prefix"/>
> <xsl:copy>
> <xsl:apply-templates select="@* | node()" mode="fix">
> <xsl:with-param name="prefix" select="$prefix"/>
> </xsl:apply-templates>
> </xsl:copy>
> </xsl:template>
>
> <xsl:template match="@id" mode="fix">
> <xsl:param name="prefix"/>
> <xsl:attribute name="id">
> <xsl:value-of select="concat($prefix, '$', .)"/>
> </xsl:attribute>
> </xsl:template>
>
> <xsl:template match="@* | text() | comment() |
> processing-instruction()" mode="fix">
> <xsl:copy/>
> </xsl:template>
>
> </xsl:stylesheet>
>
> When applied to your input (with some errors corrected) the result is
>
>
> <component>
> <assembly id="main$outerBox" width="400">
> <name>Cardboard Outer</name>
> <price id="main$outerPrice" value="200"/>
> </assembly>
> </component>
>
> which is what you described, with the exception of the component element
> where I am not sure the id is supposed to come from.
>
>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
