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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combining a xml/xsl to txt conversion

Status
Not open for further replies.

Pits21

Technical User
Oct 19, 2006
3
AU
Hi, Iam having problems with combining a xml/xsl documents into a txt output.

Code follows XML:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jokeList [
<!ELEMENT jokeList (joke)*>
<!ELEMENT joke (setUp, punchLine)*>
<!ELEMENT setUp (#PCDATA)>
<!ELEMENT punchLine (#PCDATA)>
<!ATTLIST joke category (KnockKnock|lightbulb|crossing) "crossing" >
<!ATTLIST jokes stuff (setUp|punchLine) "setUp" >

]>
<jokeList>
-
<joke category="KnockKnock">
<setUp>
Amos
</setUp>
<punchLine>
A mosquito bit me
</punchLine>
</joke>
-
<joke category="lightbulb">
<setUp>
software engineers
</setUp>
<punchLine>
none, it's a hardware problem
</punchLine>
</joke>
-
<joke category="KnockKnock">
<setUp>
Ammonia
</setUp>
-
<punchLine>

Ammonia little boy and can't reach your door bell

</punchLine>
</joke>
-
<joke category="lightbulb">
<setUp>
hardware engineers
</setUp>
<punchLine>
None. We'll fix it in software.
</punchLine>
</joke>
-
<joke category="crossing">
<setUp>
a giraffe with an echidna
</setUp>
<punchLine>
A seven metre hairbrush
</punchLine>
</joke>

<joke category="crossing">
<setUp>
a sheep with a kanagaroo
</setUp>
<punchLine>
A woolley jumper
</punchLine>
</joke>

<joke category="crossing">
<setUp>
an insomniac, an agnostic, and a dyslexic?
</setUp>
<punchLine>
Someone who stays up all night wondering if there is a Dog.
</punchLine>
</joke>
</jokeList>


XSL:

<xsl:stylesheet version="2.0"
xmlns:xsl=" xmlns="
<xsl:template match="/">
Jokes :D
<xsl:for-each select="jokeList/joke">

Joke <xsl:value-of select="normalize-space(joke)"/>
<xsl:choose> <xsl:when test="joke/@category='crossing'"></xsl:when> </xsl:choose>What do you get when you cross
<xsl:value-of select="normalize-space(jokes/stuff)"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Current output:

<?xml version="1.0" encoding="UTF-8"?>
Jokes :D


Joke What do you get when you cross


Joke What do you get when you cross


Joke What do you get when you cross


Joke What do you get when you cross


Joke What do you get when you cross


Joke What do you get when you cross


Joke What do you get when you cross


What I need to do is to select the one category which is the crossing jokes and output them. As you can see it selects the right category and thats it. It seems well formed when asking ruwf.org and compiles when I use a specialed java class file to compile it.

Any hints or suggestions? Iam going nuts about this.
 
Prima facie.
[1]
>Joke <xsl:value-of select="normalize-space(joke)"/>
[tt]Joke <xsl:value-of select="normalize-space(.)"/>[/tt]
[2]
><xsl:when test="joke/@category='crossing'"></xsl:when>
[tt]<xsl:when test="./@category='crossing'"></xsl:when>[/tt]
[3]
><xsl:value-of select="normalize-space(jokes/stuff)"/>
[tt]<xsl:value-of select="normalize-space(./stuff)"/>[/tt]
[4]
Whatever insufficient is due to me not understanding what want to be shown, such as what stuff is?
 
Fantastic thank you.

I fixed up my output so it prints out the correct jokes as selected, but stills prints out the setup and punchline of other jokes. Can I use a <xsl: if !="category/crossing">
to not print out these bits or am I missing something?
 
If you have already been using xsl:choose element, you can continue to use it for a dichotomy like that.
[tt]
<xsl:choose>
<xsl:when test="./@category='crossing'">
<!-- do etc etc -->
</xsl:when>
<xsl:eek:therwise">
<!-- do other things etc etc -->
</xsl:eek:therwise>
</xsl:choose>
[/tt]
Substantially the same as you can use xsl:if element.
[tt]
<xsl:if test="./@category='crossing'">
<!-- do etc etc -->
</xsl:if>
<xsl:if test="not(./@category='crossing')">
<!-- do other things etc etc -->
</xsl:if>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top