Subject: Re: [xsl] user defined data elements in stylesheets From: "Geert Bormans geert@xxxxxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Fri, 6 Dec 2019 11:11:35 -0000 |
Hi Mukul, document('') is what you are looking for It has some issues however. It is an interesting hack in XSLT1 if you want to avoid the use of a node-set() function But I see no reason why you would not just put the data elements inside a variable (gives you some typing on top if you want) Met vriendelijke groeten, Best regards, Geert Bormans Van: "Abel Braaksma, (Exselt) abel@xxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Aan: "xsl-list" <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Verzonden: Vrijdag 6 december 2019 11:55:47 Onderwerp: [xsl] user defined data elements in stylesheets Hi all, I'm trying to use 'user defined data elements' in an XSLT stylesheet. Following is my XSLT transformation example, XML input document: <?xml version="1.0" encoding="UTF-8"?> <root> <a val="-1"/> <a val="-4"/> <a val="5"/> <a val="3"/> <a val="2"/> </root> XSLT stylesheet (file proc1.xsl, with local absolute URI file:///e:/xslt_examples/basic/proc1.xsl): <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl=" [ http://www.w3.org/1999/XSL/Transform | http://www.w3.org/1999/XSL/Transform ] " xmlns:m_ns0=" [ http://example.com/my_meta_data | http://example.com/my_meta_data ] " exclude-result-prefixes="m_ns0" version="3.0"> <xsl:output method="xml" indent="yes"/> <!-- this is the user defined data element --> <m_ns0:names> <name>jill</name> <name>jane</name> <name>hello1</name> </m_ns0:names> <xsl:template match="root"> <result> <xsl:copy-of select="document('file:///e:/xslt_examples/basic/proc1.xsl')/xsl:stylesheet/m_ns0:names" copy-namespaces="no"/> <xsl:apply-templates select="a[number(@val) gt 0]" mode="gt0"/> <xsl:apply-templates select="a[number(@val) lt 0]" mode="lt0"/> </result> </xsl:template> <xsl:template match="a" mode="gt0"> <val><xsl:value-of select="@val"/>: positive</val> </xsl:template> <xsl:template match="a" mode="lt0"> <val><xsl:value-of select="@val"/>: negative</val> </xsl:template> </xsl:stylesheet> The above transformation produces, following result, <?xml version="1.0" encoding="UTF-8"?> <result> <m_ns0:names xmlns:m_ns0=" [ http://example.com/my_meta_data | http://example.com/my_meta_data ] "> <name>jill</name> <name>jane</name> <name>hello1</name> </m_ns0:names> <val>5: positive</val> <val>3: positive</val> <val>2: positive</val> <val>-1: negative</val> <val>-4: negative</val> </result> The above output is what I'm expecting. Following are my questions, You could see that, within my stylesheet, I've used following stylesheet instruction, <xsl:copy-of select="document('file:///e:/xslt_examples/basic/proc1.xsl')/xsl:stylesheet/m_ns0:names" copy-namespaces="no"/> I've used the absolute URI of the stylesheet document, as argument to the document() function. Is it possible, to specify the stylesheet document reference to the document() function in a portable way (i.e, not an absolute URI)? -- Regards, Mukul Gandhi [ http://www.mulberrytech.com/xsl/xsl-list | XSL-List info and archive ] [ http://lists.mulberrytech.com/unsub/xsl-list/554170 | EasyUnsubscribe ] ( [ | by email ] )
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] user defined data element, Mukul Gandhi gandhi. | Thread | [xsl] How to call an XSLT function , Costello, Roger L. c |
Re: [xsl] user defined data element, Martin Honnen martin | Date | Re: [xsl] user defined data element, Mukul Gandhi gandhi. |
Month |