Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

XSLT Question

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
This is my maiden post ...
XSL is as follows:
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/">
<xsl:apply-templates select="id('intro body end')"/>
<P>
<xsl:value-of select="id('intro body end')"/>
</P>
<P>
<xsl:value-of select="id('body end intro')"/>
</P>
<P>
<xsl:value-of select="id('in bod end')"/>
</P>
</xsl:template>
<xsl:template match="*">
<P style="color:red">
<xsl:value-of select="."/>
</P>
</xsl:template>

</xsl:stylesheet>
-----------------------XML is as below --------
<!DOCTYPE source [
<!ELEMENT chapter ANY>
<!ATTLIST chapter id ID #REQUIRED>
<!ELEMENT title ANY>
<!ATTLIST title id CDATA #REQUIRED>
<!ELEMENT text ANY>
<!ATTLIST text value ID #REQUIRED>
]>
<source>
<chapter id="intro">Introduction</chapter>
<chapter id="body">
<title id="t1">BODY</title>
<text value="text1">text text text</text>
</chapter>
<chapter id="end">THE END</chapter>
</source>
********* Output (on Saxon) is as below ******
<P style="color:red">Introduction</P>
<P style="color:red">
BODY
text text text
</P>
<P style="color:red">THE END</P>
<P>Introduction</P>
<P>Introduction</P>
<P>THE END</P>
How does <P>Introduction</P> (penultimate line in the output appear). Can somebody explain
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It might be because of the place you are using the id function.
In <xsl:apply-templates> it selects all the text value of the nodes.
In <xsl:value-of> it selects the only first node's text value which is in the resultant node set.
 
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you were expecting the following for the penultimate line -
===========================================
BODY
text text text
INSTEAD OF .............
Introduction
============================================
The reason for this is that the function
id("body intro end") will select 3 nodes as it traverses "down the tree". This is the reason why "intro" stuff always happens to be the first node.
Please run this simple stylesheet to confirm this -
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/">
<P>
<xsl:for-each select="id('body intro end')">
<xsl:value-of select="."/>
</xsl:for-each>
</P>
</xsl:template>
<xsl:template match="*">
<P style="color:red">
<xsl:value-of select="."/>
</P>
</xsl:template>
</xsl:stylesheet>
 
Kris Mann
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me give that a try, and I will get back to you
 
Kris Mann
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks a bunch Jayadev,
That works for me .
 
I love a good mentalist. And so does this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic