Subject: [xsl] user defined data elements in stylesheets From: "Mukul Gandhi gandhi.mukul@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Fri, 6 Dec 2019 10:55:42 -0000 |
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" xmlns:m_ns0="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"> <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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] best practices for using , Dimitre Novatchev dn | Thread | Re: [xsl] user defined data element, Martin Honnen martin |
Re: [xsl] best practices for using , Mukul Gandhi gandhi. | Date | Re: [xsl] user defined data element, Martin Honnen martin |
Month |