How to declare a variable

Having trouble installing Oxygen? Got a bug to report? Post it all here.
Boreas
Posts: 86
Joined: Wed Feb 09, 2011 10:43 pm

How to declare a variable

Post by Boreas »

Hello,

We have two types of documents to generate, one that requires chapter numbering, and the other requires no numbering. I was able to create a condition in the custom.xsl file to generate the document with or without numbering base on the book title. Obviously putting a condition on a book title does not work since are documents don't all have the same name.

I tried using <xsl:when test="($otherprops='number')">
But I get an error message saying that Variable otherprops is undeclared. How and where can I declare this variable? Or is there another variable I should be using. This variable needs to be associated to the ditamap.

Kind regards
Carole



Here is the code I used.

Code: Select all

[code]<xsl:template match="*" mode="getTitle">
<xsl:variable name="topic" select="ancestor-or-self::*[contains(@class, ' topic/topic ')][1]" />
<xsl:variable name="id" select="$topic/@id" />
<xsl:variable name="mapTopics" select="key('map-id', $id)" />
<fo:inline>
<xsl:choose>
[b] <xsl:when
test="($bookTitle='number')">[/b]
<xsl:for-each select="$mapTopics[1]">
<xsl:choose>
<!--xsl:when test="parent::opentopic:map"/-->
<xsl:when test="ancestor-or-self::*[contains(@class, ' bookmap/frontmatter ') or contains(@class, ' bookmap/backmatter ')]" />
<xsl:when test="ancestor-or-self::*[contains(@class, ' bookmap/appendix ')]">
<xsl:number count="*[contains(@class, ' map/topicref ')] [ancestor-or-self::*[contains(@class, ' bookmap/appendix ')]]" format="A.1.1" level="multiple" />
</xsl:when>
<xsl:otherwise>
<xsl:number count="*[contains(@class, ' map/topicref ')] [not(ancestor-or-self::*[contains(@class, ' bookmap/frontmatter ')])]" format="1.1" level="multiple" />
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</fo:inline>
<xsl:text> </xsl:text>
<xsl:apply-templates />
</xsl:template>
[/code]
Radu
Posts: 9053
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to declare a variable

Post by Radu »

Hi Carole,

So how exactly did you mark the bookmap? Did you set the @otherprops attribute on the root element or on the title?
You should have use instead the @outputclass attribute because profiling attributes, like @otherprops usually get removed in the filtering stage.
And in the XSLT you could have done stuff like:

<xsl:when test="//*[contains(@class, 'topic/title')][@outputclass='testValue']">

Or you could have used the <data> DITA element in the metadata section like:

Code: Select all


.......
<map title="Growing Flowers">
<topicmeta>
<data name="chapterNumbering" value="yes"/>
</topicmeta>

.........
and again match it from the XSLT code using an XPath expression.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Boreas
Posts: 86
Joined: Wed Feb 09, 2011 10:43 pm

Re: How to declare a variable

Post by Boreas »

Hello,
I am still unable to generate the document and I think it is because I don't quite get all the connexions between all the files, and I obviously have no skills in code writing. Thanks for being patient with me.

In the dita map I added

Code: Select all

<othermeta name="ChapterNumbering" content="yes"/>
The <data> attribute did not seem to be recognised.

In the commons.xsl file , under

Code: Select all

<xsl:template match="*[contains(@class, ' topic/othermeta ')]">
I added

Code: Select all

<xsl:when test="//*[contains(@class, 'topic/title')][@othermeta='testValue']">
I was not sure the code was ok, nor did I palce it in the proper file.

In the custom.xsl file I added

Code: Select all


 <xsl:when test="($othermeta='yes')">

thanks again for your help
Radu
Posts: 9053
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to declare a variable

Post by Radu »

Hi Carole,

Here's my suggestion:

1) You leave the commons.xsl as it is, without any changes.
2) In the custom.xsl you use this construct:

Code: Select all

<xsl:when test="//othermeta[@name="ChapterNumbering"][@content="yes"]">
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Boreas
Posts: 86
Joined: Wed Feb 09, 2011 10:43 pm

Re: How to declare a variable

Post by Boreas »

Beautifull! thanks!

the only change I made was for the quotes. Apparently oXygen does not like nested double quotes :?

Code: Select all


<xsl:when test="//othermeta[@name='ChapterNumbering'][@content='yes']">
thank you for your precious help. Without your help (and the help of the rest of the team) , I would not had been able to do half the customisation I needed. You answer fast, answers are complete and most of all, you are patient!

Carole
Radu
Posts: 9053
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to declare a variable

Post by Radu »

Hi Carole,

You were right about the quotes, whenever you already have double quotes around an attribute value, you must use single quotes inside it. The XML specification does not allow nesting double quoted.
And thanks for the kind words.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply