Subject: Including files into a stylesheet From: Joe Plant <Joe.Plant@xxxxxxxxxxxxxxx> Date: Wed, 2 Aug 2000 11:59:41 +0100 |
Hi all, This is my first post to the list. I have an application build around MSXML3 (july edition) where I need to convert an xml input file into an xml output file. Input.xml <Input> <DIV ID="Firstname">Joe</DIV> <DIV ID="Surname">Bloggs</DIV> <DIV ID="Phone">123456789</DIV> <DIV ID="Fax">987654321</DIV> <DIV ID="Salary" CURRENCY="GBP">100,000</DIV> </Input> Output.xml <Output> <Field name="Name" Type="Text"> <Value>Joe Bloggs</Value> </Field> <Field name="Phone" Type="Text"> <Value>123456789</Value> </Field> <Field name="Fax" Type="Text"> <Value>987654321</Value> </Field> <Field name="Salary" Type="Numeric"> <Value>100000</Value> </Field> <Field name="SalaryCurrency" Type="Text"> <Value>GBP</Value> </Field> </Output> The xsl stylesheet that I use to translate the input to the output is as follows Translate.xsl <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes" encoding="UTF-8"/> <xsl:template match="/"> <!-- The following variables are defined : varName varTelephone varFax varSalary varSalaryCurrency --> <xsl:variable name="varName"> <xsl:if test="Input/DIV[(@ID='Firstname') or (@ID='Surname')]"> <xsl:variable name="_varFirstname"> <xsl:if test="not(Input/DIV[@ID='Firstname']='NA')"> <xsl:value-of select="Input/DIV[@ID='Firstname']"/> </xsl:if> </xsl:variable> <xsl:variable name="_varSurname"> <xsl:if test="not(Input/DIV[@ID='Surname']='NA')"> <xsl:value-of select="Input/DIV[@ID='Surname']"/> </xsl:if> </xsl:variable> <xsl:value-of select="$_varFirstname"/> <xsl:if test="not(($_varFirstname='') or ($_varSurname=''))"> <!-- insert a space (0x20) between the firstname and surname --> <xsl:text> </xsl:text> </xsl:if> <xsl:value-of select="$_varSurname"/> </xsl:if> </xsl:variable> <xsl:variable name="varTelephone" select="Input/DIV[@ID='Phone']"/> <xsl:variable name="varFax" select="Input/DIV[@ID='Fax']"/> <xsl:variable name="varSalary"> <xsl:apply-templates select="Input/DIV[@ID='Salary']" mode="Value"/> </xsl:variable> <xsl:variable name="varSalaryCurrency"> <xsl:apply-templates select="Input/DIV[@ID='Salary']" mode="Currency"/> </xsl:variable> <Output> <Field Name="Name" Type="Text"> <Value> <xsl:value-of select="$varName"/> </Value> </Field> <Field Name="Phone" Type="Text"> <Value> <xsl:value-of select="$varTelephone"/> </Value> </Field> <Field Name="Fax" Type="Text"> <Value> <xsl:value-of select="$varFax"/> </Value> </Field> <Field Name="Salary" Type="Numeric"> <Value> <xsl:value-of select="$varSalary"/> </Value> </Field> <Field Name="SalaryCurrency" Type="Text"> <Value> <xsl:value-of select="$varSalaryCurrency"/> </Value> </Field> </Output> </xsl:template> <xsl:template match="*" mode="Value"> <xsl:variable name="_varValue" select="translate(.,'-01234567890(),NA','-01234567890-')"/> <xsl:value-of select="$_varValue"/> </xsl:template> <xsl:template match="*" mode="Currency"> <xsl:value-of select="@CURRENCY"/> </xsl:template> </xsl:stylesheet> This works fine....althought I have another stylesheet that also uses the same variables. Rather than copying the variable evaluation into the new stylesheet, is it possible to define the variables in a file and then include them into the stylesheet. I have tried using <xsl:import href=varDeclaration.xsl/> and <xsl:include href=varDeclaration.xsl/> but with no success. It seems that I need to define the namespace in any files that I wish to include (and they are not valid at the positions that I have specified). Also I seem to have problems using variables defined in one template in another. ie. i have to define and use the variables in one template only. Thanks in advance, Joseph Plant Joe.Plant@xxxxxxxxxxxxxxx XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: Heeeeeeeeelp, Thorbjørn Ravn Ander | Thread | RE: Including files into a styleshe, Kay Michael |
Re: Saxon VS XT, Sebastian Rahtz | Date | RE: MSXML Whitespace handling, Paulo Gaspar |
Month |