[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[xsl] XSLT string substituion
Subject: [xsl] XSLT string substituion From: Ann Marie Rubin <Annmarie.Rubin@xxxxxxx> Date: Tue, 02 Nov 2004 10:12:48 -0500 |
Hello experts, I need to use XSLT for a part of a project and have very little experience with its syntax. The problem is to replace text strings in this soruce xml file with a value supplied by a variable. For example, replace temporary-directory="./temp" with temporary-directory="/var/tmp" We will use a program that performs the variable substitution and then calls the XSLT processor to perform the transform. The program calls XSLT to validate the transformation BEFORE substituting the variables, so the XLST stylesheet must work with the variable formats included. The variables must be in this format: :[var] When I substitute variables in this format (:[var}) in the XSLT stylesheet, the transformation fails with the error: Prefix must resolve to a namespace. When I enclose the var in single quotation marks (':[var]'), this message is displayed: A node test that matches either NCName:* or QName was expected. [12] How can I pass this variable syntax in the XSLT stylesheet? Thanks for your help, Ann Marie Source XML file: <?xml version="1.0"?> <!DOCTYPE orion-web-app PUBLIC "-//ORACLE//DTD OC4J Web Application 9.04//EN" "http://xmlns.oracle.com/ias/dtds/orion-web-9_04.dtd"> <orion-web-app deployment-version="9.0.4.0.0" temporary-directory="./temp" internationalize-resources="false" default-mime-type="application/octet-stream" > <!-- Uncomment this element to control web application class loader behavior. --> <web-app-class-loader search-local-classes-first="true" include-war-manifest-class-path="true" /> </orion-web-app> This stylesheet A (without the variable format) works correctly to replace the text: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes" method="xml"/> <xsl:template match="*|@*|text()|comment()"> <xsl:copy> <xsl:apply-templates select="*|@*|text()|comment()"/> </xsl:copy> </xsl:template> <xsl:template name="copy-content-no-attrs"> <xsl:apply-templates select="processing-instruction()|comment()|*|text()"/> </xsl:template> <xsl:template match="orion-web-app[@deployment-version]"> <xsl:copy> <xsl:attribute name="deployment-version">9.0.4.1</xsl:attribute> <xsl:apply-templates select="@*[not(name()='deployment-version')]"/> <xsl:call-template name="copy-content-no-attrs"/> </xsl:copy> </xsl:template> <xsl:template match="web-app-class-loader[@search-local-classes-first]"> <xsl:copy> <xsl:attribute name="search-local-classes-first">FALSE</xsl:attribute> <xsl:apply-templates select="@*[not(name()='search-local-classes-first')]"/> <xsl:call-template name="copy-content-no-attrs"/> </xsl:copy> </xsl:template> </xsl:stylesheet> This stylesheet B (with the variable format) fails: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes" method="xml"/> <xsl:template match="*|@*|text()|comment()"> <xsl:copy> <xsl:apply-templates select="*|@*|text()|comment()"/> </xsl:copy> </xsl:template> <xsl:template name="copy-content-no-attrs"> <xsl:apply-templates select="processing-instruction()|comment()|*|text()"/> </xsl:template> <xsl:template match="orion-web-app[@:[entryName]]"> <xsl:copy> <xsl:attribute name=":[entryName]">:[value]</xsl:attribute> <xsl:apply-templates select="@*[not(name()=':[entryName]')]"/> <xsl:call-template name="copy-content-no-attrs"/> </xsl:copy> </xsl:template> <xsl:template match="web-app-class-loader[@:[entryName]]"> <xsl:copy> <xsl:attribute name=":[entryName]">:[value]</xsl:attribute> <xsl:apply-templates select="@*[not(name()=':[entryName]')]"/> <xsl:call-template name="copy-content-no-attrs"/> </xsl:copy> </xsl:template> </xsl:stylesheet>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Iterating over the nodes , Geert Josten | Thread | Re: [xsl] XSLT string substituion, David Carlisle |
Re: [xsl] A question on optimizatio, David Carlisle | Date | [xsl] Iterating over the nodes in a, Jochen Wiedmann |
Month |