Can you add write XML into an XSL sheet that it can use?

G

gwoodhouse

Hello again,

Sorry for yet another question so early but this XSLT stuff is pretty
hard to get a grips on.

Ok, the question is: if im transforming some XML using an XSL
stylesheet, will i be able to reference XML written into the XSL which
is calling it (for constant values) ie.

<!--Xslsheet.xsl -->
<bob key="jim">hello</bob>

<xml:value-of select="bob"> or <xml:value-of select="/bob"> or
<xml:value-of select="/bob[@key='jim']">
<!--Xslsheet.xsl -->

Will "hello" be printed in the output?

I know its a small question but its very hard to find if this is true
(when im trying it now, getting no errors but its not printing out
"hello").

Thanks for your help on this (and on my last question!)

Graeme
 
P

Pavel Lepin

Ok, the question is: if im transforming some XML using an
XSL stylesheet, will i be able to reference XML written
into the XSL which is calling it (for constant values) ie.

<bob key="jim">hello</bob>

Note that this must be namespaced or your XSLT processor
will choke on it.
<xml:value-of select="bob"> or <xml:value-of
select="/bob"> or <xml:value-of select="/bob[@key='jim']">

Although by no means mandatory, xsl: namespace prefix is
usually used for XSLT namespace to avoid confusion.
Will "hello" be printed in the output?

No. Unless you specify some other document, your XPath
expressions are evaluated on the document you're
processing. You need to use document('') to evaluate
expressions on stylesheet itself; see examples posted
yesterday.

<xsl:value-of
select="document('')/xsl:stylesheet/*[@key='jim']"/>
 
G

gwoodhouse

Thanks Pavel,

That just made it click. I understand most of the code people posted
yesterday now! :)

Thanks again,

Graeme
 
G

gwoodhouse

Current code:

<xsl:template match="decode">
<xsl:param name="cats"/>
<xsl:variable name="car" select="substring-before($cats,'|')"/>
<xsl:variable name="cdr" select="substring-after($cats,'|')"/>
<xsl:apply-templates select="document('')/xsl:stylesheet/*[@key=
$car]/@value"/>
<xsl:if test="$cdr">
<xsl:call-template name="decode">
<xsl:with-param name="cats" select="$cdr"/>
</xsl:call-template>
</xsl:if>
</xsl:template>

<xsl:template match="subjecten">
<xsl:choose>
<xsl:when test="contains(.,'|')">
<datafield tag="650" ind1=" " ind2=" ">
<subfield code="a">
<xsl:call-template name="decode">
<xsl:with-param name="cats" select="."/>
</xsl:call-template>
</subfield>
</datafield>
</xsl:when>
<xsl:eek:therwise>
<datafield tag="650" ind1=" " ind2=" ">
<subfield code="a">
<xsl:value-of select="."/>
</subfield>
</datafield>
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>

Unfortunatly my parser doesnt like calling "decode" from within the
"decode" template?

ERROR: 'file:///C:/Development/ZWebService/xsl/bp.xsl: line 129:
Template 'decode' not defined in this stylesheet.'

Pavel: I got most of this from the code you posted in the other block,
do you know why im getting this error?
 
M

Martin Honnen

Current code:

<xsl:template match="decode">

Unfortunatly my parser doesnt like calling "decode" from within the
"decode" template?

ERROR: 'file:///C:/Development/ZWebService/xsl/bp.xsl: line 129:
Template 'decode' not defined in this stylesheet.'

You need
<xsl:template name="decode">
above if you later want to use xsl:call-template name="decode".
match="decode" is only useful if you have elements named "decode" and
want to apply templates to them.
 
G

gwoodhouse

Thanks Martin,

To anyone who uses these threads in the future, this is the working
code i ended up with:

<xsl:template name="decode">
<xsl:param name="cats"/>
<xsl:variable name="car" select="substring-before($cats,'|')"/>
<xsl:variable name="cdr" select="substring-after($cats,'|')"/>
<xsl:value-of select="document('')/xsl:stylesheet/*[@key=$car]/
@value"/>
<xsl:choose>
<xsl:when test="contains($cdr, '|')">, <xsl:call-template
name="decode"><xsl:with-param name="cats" select="$cdr"/></xsl:call-
template> </xsl:when>
<xsl:eek:therwise>, <xsl:value-of select="document('')/xsl:stylesheet/
*[@key=$cdr]/@value"/></xsl:eek:therwise>
</xsl:choose>
</xsl:template>

<xsl:template match="subjecten">
<xsl:choose>
<xsl:when test="contains(.,'|')">
<datafield tag="650" ind1=" " ind2=" ">
<subfield code="a">
</xsl:call-template>
</subfield>
</datafield>
</xsl:when>
<xsl:eek:therwise>
<datafield tag="650" ind1=" " ind2=" ">
<subfield code="a">
<xsl:value-of select="."/>
</subfield>
</datafield>
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>

Thanks again everyone!!

Graeme
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,900
Latest member
Nell636132

Latest Threads

Top