[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Transforming Locally Declared Namespaces into Glob
> I had hoped for a more generic solution because we are working with > arbitrary schema. It's probably possible to do something more generic but it all depends... for example, instead of hardcoding a set of namespace templates in the stylesheet > <xsl:template match="a:*"> > <xsl:element name="a:{local-name()}"> > <xsl:copy-of select="@*"/> > <xsl:apply-templates/> > </xsl:element> > </xsl:template> You could do <xsl:template match="*"> <xsl:variable name="prefix"> .... hmmm .... </xsl:variable> <xsl:element name="{$prefix}:{local-name()}"> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:element> </xsl:template> where .... hmmm .... is replaced by er something. the requirements being that a) you want to get the same prefix for every element in each namespace b) you want a different prefix for each namespace c) you want a namespace node declaring that prefix on the top most element of the output One way to achieve that, as in my first post was to assume you know all teh namespaces that can occur, and arbitrarily assign them fixed prefixes in the stylesheet, ignoring any prefixes used (or not) in the source. If you can't make that assumption, you have to work a bit harder. eg if you keyed every element by its namespace <xsl:key name="ns" match="*" use="namespace-uri()"/> then hmm could be <xsl:value-of select="generate-id(key('ns',namespace-uri(current()))[1])"/> whch would use as a prefix a (generated) id of the first element in the source that had that namespace, so clearly that satisfies a and b above. to satisfy c you'd have to use a node-set extension function: First generate the output as above into a variable, then use node-set so you can post process the variable, and then just xsl:copy-of all teh namespace nodes up to the top. David -- The LaTeX Companion http://www.awprofessional.com/bookstore/product.asp?isbn=0201362996 http://www.amazon.co.uk/exec/obidos/tg/detail/-/0201362996/202-7257897-0619804 ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|