XM to XSLT Newbie

Here should go questions about transforming XML with XSLT and FOP.
AshKutt
Posts: 8
Joined: Tue Oct 02, 2012 4:53 am

XM to XSLT Newbie

Post by AshKutt »

Hello Gurus,

I'm new to XSLT and have so far only seen XML documents. But now I have been given a task to convert a XML document to XSLT. I downloaded Oxygen but do not know where to start etc.

If I have this dummy.xml file.How would I start this in Oxygen and write code for xslt and see th output as pipe delimited file. Output should be Professional JINI|Sing Li|Wrox Publications.

Code: Select all

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<LIBRARY>
<BOOK>
<TITLE>Professional JINI</TITLE>
<AUTHOR>Sing Li</AUTHOR>
<PUBLISHER>Wrox Publications</PUBLISHER>
</BOOK>
</LIBRARY>
I know i'm probably asking the basic question, but since im new to this technology and the tool, I thought I would ask for help. Any help will be greatly appreciated.

Thanks
Ash
AshKutt
Posts: 8
Joined: Tue Oct 02, 2012 4:53 am

Re: XM to XSLT Newbie

Post by AshKutt »

After playing a bit with the tool, I was able to create the xslt file. However, I have few questions.

1) How do I do if conditions?

Say an employee has Prefefferd Last Name and Legal Last name

So the condition should say If Preferred name exists the use preferred name else use Last name.

2) How do I check for null values? meaning if value is blank then i want to insert 'xxx' on the pipe delimited file

3) How do I use a running counter ?

Sorry for all these basic questions. Still getting my head around this.


Thanks
Ash
adrian
Posts: 2879
Joined: Tue May 17, 2005 4:01 pm

Re: XM to XSLT Newbie

Post by adrian »

Hello,

1. Assuming you're in the context where the name and last name elements are specified:
You can use either xsl:if or xsl:choose:

Code: Select all

<xsl:if test="preferredLastNameElement">
...
</xsl:if>
<xsl:if test="not(preferredLastNameElement)">
...
</xsl:if>
or

Code: Select all

<xsl:choose>
<xsl:when test="preferredLastNameElement">
...
</xsl:when>
<xsl:when test="legalLastNameElement">
...
</xsl:when>
</xsl:choose>
2. To check for empty values:
<xsl:if test="preferredLastNameElement/text()">
To check for values that contain only space characters:
<xsl:if test="normalize-space(preferredLastNameElement/text())">

3.

Code: Select all

<xsl:for-each select="1 to n">
...
</xsl:for-each>
Note that the XML context is lost inside this for-each, instead, the context(.) is the current value of the counter. So you may want to save the XML context in a variable before this.
e.g.

Code: Select all

<xsl:variable name="context" select="."/>
<xsl:for-each select="1 to n">
...
<xsl:value-of select="$context"/>
</xsl:for-each>
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply