XSL Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This might not be the right NG for this, but i couldn't get a reply on the
XSL forum.

<xsl:if test="fTOC[starts-with(@filename, '5')]">
<xsl:element name="Section1">
<xsl:attribute name="titleRef">Section 1 - Section
One</xsl:attribute>
<xsl:for-each select="fTOC[starts-with(@filename, '5')]">
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:element>
</xsl:if>

I am going through a list of files starting with '5' and placing them under
the header "Section 1 - Section One", which is hard-coded right now. I want
to populate the titleRef dynamically... i.e if i get an item starting with
'5', I would like to open the first such item and retrieve the value of
<ChapterNum> and use that to fill the titleRef.

I am very new to xml transformations, can somebody plz help me with some
code on how to accomplish this?

Thanks.
 
Can you clarify your example at all? However, at the core it will be
something like:

(watch for wrap - this is all one line)
<xsl:attribute name="titleRef"><xsl:value-of
select="fTOC[starts-with(@filename,'5')][1]/ChapterNum"/></xsl:attribute>
(end line)

However, I'm not sure if you want the '5' to be dynamic... if so you
need to define how to identify this - substring(@filename,1,1) is
crude and covers 5, 50, 51, etc - but unsure what your scenario is.

Have I missed the point?

Marc
 
Thanks for the reply Marc.

I have a booklist that contains a list of all files. I am trying to
group the files that start with 5 under one header. lets say we have a few
files like
5-1
5-2
5-3...

chapterNum contains the value that should be the header under which all the
files starting with 5 should be held. This can be taken by opening the first
'5' file i.e 5-1 and reading the chapterNum element from there. I want to
read the chapterNum value from only the first '5' file and then use it as a
header for grouping all the '5' files.

Thanks again.
 
For a more useful reply, you really are going to have to post some
kind of xml. I'm guessing it would involve a range of string lookup
specific to your example, indexOf[*], substring-after, etc, plus some
mode simple operators, such as [1] for "first".

However, if you can influence the xml, you could make your life a
*lot* easier by not using delimiters in data - i.e.

<file chapter="5" section="1">...</file>
is a *lot* easier to process than <file key="5-1"/>

But I'm sorry to say that other than these pointers, there isn't
enough detail in your post to give a better answer.

*: see places like http://www.biglist.com/lists/xsl-list/archives/200507/msg00750.html
 
Back
Top