[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Generating an XSL from an XML
Hi Rémy, > i would like to know if there won't be any problems using an XSL > stylesheet to generate another stylesheet. > > For example, i wanted to use an xml defining a format, and generate > the default xsl stylesheet able to parse an xml using that format > into a text file. > > I was inquisitive to know whether there were another option than > using a <![CDATA section for every XSL instruction i wanted to > generate, so that the parser didn't try to execute them. Absolutely. This is the role of the xsl:namespace-alias element. The xsl:namespace-alias element allows you to put all the instructions that you want to generate in a different namespace (whatever you like), so that they're not treated as XSLT instructions, and then automatically move them into the XSLT namespace in the result tree, so that they end up being XSLT instructions. To use it, you define the alias namespace in the document element (here I'm using the default namespace as the alias namespace): <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/XSL/TransformAlias"> ... </xsl:stylesheet> The xsl:namespace-alias element is a top-level element, with two attributes: stylesheet-prefix, which specifies the prefix of the alias namespace in the stylesheet; and result-prefix, which specifies the prefix of the namespace that elements in that namespace should be placed in within the result tree. You can use #default to indicate the default namespace (no prefix) in either attribute: <xsl:namespace-alias stylesheet-prefix="#default" result-prefix="xsl" /> Then you can just use literal result elements to create the XSLT instructions. For example: <xsl:template match="foo"> <xsl:for-each select="bar"> <value-of select="{@xpath}" /> </xsl:for-each> </xsl:template> creates an xsl:value-of instruction for each bar element, whose select attribute has the value of the xpath attribute on the bar element. The other method is to use xsl:element/xsl:attribute, but using a namespace alias is a lot easier if you're needing to create a lot of instructions. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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
|