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/7/2008 1:47:00 PM Oh wicked! That did the trick. Thanks very much 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 | |||
|
