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

XML/XSL Transformation Help 1

Status
Not open for further replies.

FlyerNut

MIS
Nov 7, 2001
33
US
First, I have only worked with this for a week, so please bear with me.

I have this xml file:

<job client="127.0.0.1" id="1150317129" name="1150317129" product="apollo" scale="Merril" user="Merril">
<publication document="Multiboxes" mergepages="true" name="19" product="Merril" type="Test 1"></publication>
<channel name="Wave2Channel" postaction="preview"></channel>
<editorial>
<articlegroup id="1" name="Group 1" sortitem="" sortorder="" sorttype="">
<article id="1" ignored="false" linkable="true" name="1" placed="true">
<text id="1" name="Portfolio" placed="true"><content><![CDATA[Portfolio]]></content></text>
</article>
</articlegroup>
<articlegroup id="2" name="Group 2" sortitem="1" sortorder="ascending" sorttype="string">
<article id="1" ignored="false" linkable="true" name="1" placed="true">
<text id="1" name="sl1" placed="true"><content><![CDATA[Common Stock]]></content></text>
<text id="2" name="Sl2" placed="true"><content><![CDATA[Bangladesh]]></content></text>
<text id="3" name="Sl3" placed="true"><content><![CDATA[Housing]]></content></text>
<text id="4" name="Detail" placed="true"><content><![CDATA[asdfljasdjfk]]></content></text>
</article>
<article id="2" ignored="false" linkable="true" name="2" placed="true">
<text id="1" name="sl1" placed="true"><content></content></text>
<text id="2" name="Sl2" placed="true"><content></content></text>
<text id="3" name="Sl3" placed="true"><content><![CDATA[Textiles]]></content></text>
<text id="4" name="Detail" placed="true"><content><![CDATA[asdf;lsdkf;lakfd]]></content></text>
</article>
</articlegroup>
</editorial>
</job>



and this XSL file:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl=" version="1.0">
<xsl:eek:utput method="text"/>
<xsl:template match="publication" >
<xsl:value-of select="@document"/>

</xsl:template>
</xsl:stylesheet>


From all of the tutorials I've read, I should only be returning the document part of the publication element, so why am I receiving this when running it through a transform:

MultiboxesPortfolioCommon StockBangladeshHousingasdfljasdjfkTextilesasdf;lsdkf;lakfd


Sorry if this is a basic error, but I'm trying to understand what I'm doing wrong and am getting frustrated. If you could also provide any tutorial or other sites I'd appreciate it as well.
 
It is a basic error that even experienced XSLT users fall into occasionally. You are seeing the effect of built-in template rules. The built-in rule for text nodes is what is copying all the other text nodes over to the output document. Try:
Code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] version="1.0">
    <xsl:output method="text"/>
    <xsl:template match="publication" >
        <xsl:value-of select="@document"/>
        
    </xsl:template>
	<xsl:template match="text()"/>
</xsl:stylesheet>
The last template will match all the text nodes but emit nothing into the output.

Tom Morrison
 
Tom,

Thanks for your help, it's greatly appreciated.

Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top