1

I want to use data from XML to populate a class:

E.g.

<p class="<xsl:value-of select="a:Subject"/>">English</p>

Which would generate:

<p class="English">English</p>

IS this possible?

3
  • That is an HTML class, it has nothing to do with CSS (except that CSS can reference it). You might also want: lang="en". Commented Sep 14, 2009 at 14:09
  • @David He is trying to add the class value which is coming from an XML document in the output of an XSLT transformation. Commented Sep 14, 2009 at 14:12
  • @Thiyagaraj — I know what he is trying to do. The value of an HTML class attribute is still an HTML class, not a CSS class. There is no such thing as a CSS class, except as a confusing phrase which sometimes means "An HTML class", sometimes means "A CSS class selector", sometimes means "A CSS selector of any kind" and sometimes means "A CSS rule-set". The term "CSS class" is confusing and should be avoided (especially when you can't get the context without clicking through from the list of questions to the actual question). Commented Sep 14, 2009 at 14:21

2 Answers 2

4

Yes, it is possible, use the below code with Attribute Value Template

<p class="{a:Subject}">English</p>
Sign up to request clarification or add additional context in comments.

Comments

1

Yes via the <xsl:attribute>

Ex:

<xsl:template match="yourXPath">
  <p>
  <xsl:attribute name="class">
      <xsl:value-of select="a:Subject"/>
  </xsl:attribute>
  </p>
</xsl:template>

2 Comments

That empty attribute will rise an error, not because it's empty, but because it's output after a text node (xsl:value-of instruction). Maybe you want to put the xsl:value-of instruction inside the xsl:attribute one?
@Alejandro: yes, it was a big mistake from me. Corrected. Thx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.