Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSLT Question 1

Status
Not open for further replies.

Tiamose

Programmer
Nov 13, 2007
10
0
0
VN
Hi all,

I have a question about XSLT and I hope you can help me.

I have a XML file like that

<book>
<title>
Title here
</title>
<author>
Author name here
</author>
<content>
content here
</content>
</book>


<book>
<author>
Author name here
</author>
<content>
content here
</content>
</book>

<book>
<content>
content here
</content>
</book>

I want to extract title of these books, and ONLY IF there's no title then I'll extract the Author name. If there is neither title nor author then nothing is extracted.

With XSLT, I know how to extract title, or author, or both. However I don't know how to extract author only if there is no title. Can anyone help me?
 
The conduct of reasoning is procedural, and so it is in xsl as well.
[tt]
<xsl:template match="book">
<xsl:choose>
<xsl:when test="normalize-space(title) != ''">
<!-- do extract title -->
</xsl:when>
<xsl:eek:therwise>
<xsl:choose>
<xsl:when test="normalize-space(author) != ''">
<!-- do extract author -->
<xsl:when>
<xsl:eek:therwise>
<!-- do nothing -->
</xsl:eek:therwise>
</xsl:choose>
</xsl:eek:therwise>
<xsl:choose>
</xsl:template>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top