How to declare a variable
Having trouble installing Oxygen? Got a bug to report? Post it all here.
-
- Posts: 86
- Joined: Wed Feb 09, 2011 10:43 pm
How to declare a variable
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.
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]
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
<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]
-
- Posts: 9449
- Joined: Fri Jul 09, 2004 5:18 pm
Re: How to declare a variable
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:
and again match it from the XSLT code using an XPath expression.
Regards,
Radu
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>
.........
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 86
- Joined: Wed Feb 09, 2011 10:43 pm
Re: How to declare a variable
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 addedThe <data> attribute did not seem to be recognised.
In the commons.xsl file , under
I added
I was not sure the code was ok, nor did I palce it in the proper file.
In the custom.xsl file I added
thanks again for your help
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"/>
In the commons.xsl file , under
Code: Select all
<xsl:template match="*[contains(@class, ' topic/othermeta ')]">
Code: Select all
<xsl:when test="//*[contains(@class, 'topic/title')][@othermeta='testValue']">
In the custom.xsl file I added
Code: Select all
<xsl:when test="($othermeta='yes')">
thanks again for your help
-
- Posts: 9449
- Joined: Fri Jul 09, 2004 5:18 pm
Re: How to declare a variable
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:
Regards,
Radu
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"]">
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 86
- Joined: Wed Feb 09, 2011 10:43 pm
Re: How to declare a variable
Beautifull! thanks!
the only change I made was for the quotes. Apparently oXygen does not like nested double quotes
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
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']">
Carole
-
- Posts: 9449
- Joined: Fri Jul 09, 2004 5:18 pm
Re: How to declare a variable
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
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
<oXygen/> XML Editor
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service