Ksice
Ksice

Reputation: 3327

Xslt: xml to html. Something depending on parameters

1)I have an XML file with the structure that I don't want really change.

I'm using xslt to show my xml as html.

But I have some text on html-form depending on language, that is declared in xml. So I should dynamically choose the right language and depending on it show the right text.

Is it possible to declare constants in xslt and then choose the right one?

2)And another question. I have

<meta http-equiv="Content-Type" content="text/html; charset=mycharSet" />

where mycharset is

<xsl:value-of select="root/CHARACTER_SET"/>

How can I insert this to meta tag?

Upvotes: 1

Views: 80

Answers (1)

FailedDev
FailedDev

Reputation: 26940

Within the XSLT stylesheet declare global parameters e.g. :

<xsl:param name="lang"/>

or in xslt 2.0

<xsl:param name="lang" required="yes" as="xs:string"/> etc.. ..

Then when calling your xslt pass the corresponding parameter and change the "text" depending on the value of the parameter :

<xsl:choose>
  <xsl:when test="$lang = 'English'"> ... 

Hope it helps.

Edit:

Regarding your second question :

<xsl:variable name="charSet" select="root/CHARACTER_SET"/>
<meta http-equiv="Content-Type" content="text/html; charset={$charSet}" />

Upvotes: 1

Related Questions