• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help in XML & XSL

 
Md Fizal
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an XML source and from where I fetch one of the element value using XSL file. But the problem I am facing is that, instead of getting only one value from the source XML, I am getting the valus of all the elements in the source XML. If I remove the 'namespace' attribute in the document element of the source XML, I am getting the value correctly. Could someone pls help me why it is happening so?
XML file
<HR>
<?xml version="1.0"?>
<GetArticle xmlns="com:test eveloper"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" version="1.0"
xml:lang="en">
<Control>
<SessionID>WlpaWlpaaMjAwMTE </SessionID>
</Control>

<Request>
<AccessionNoDetails>
<AccessionNo>ppgz000020</AccessionNo>
<Scope>FULL</Scope>
</AccessionNoDetails>
</Request>
</GetArticle>
<HR>
XSL
<HR>
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl utput method="html"/>

<xsl:template match="/">
<TABLE BORDER="1">
<TR>
<TD> <I>TEST</I> </TD>
</TR>
<TR>
<TD> <B> ROW 1 </B> </TD>
</TR>
<TR>
<TD> <B> <xsl:apply-templates/></B> </TD>
</TR>
</TABLE>
</xsl:template>

<xsl:template match="GetArticle/Control">
<xsl:value-of select="SessionID"/>
</xsl:template>

<xsl:template match="GetArticle/Request">

</xsl:template>

</xsl:stylesheet>
 
Vivek Saxena
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fiz,
Let me try to help you. I can see the problem with your XML file and XSL file.

All the elements in your source XML file is in �com:test: developer� namespace. While in your XSL file all the �xsl:template� looking for an element in source document which is not in any anmespace and it does not find any element in source document which is not in any namespace. All the defaults templates will be executed in this case and this is how you are getting all the value.
Once you remove the namespace declaration from source file then all the elements in source XML file do not belongs to any namespace and the templates in XSL documents get executed.

If you do following change in your source XSL file then you will get desired results.

I am assuming that the namespace string in source document is �com:test: developer�, in case if it is different then change it accordingly in above XSL file.
I hope this make things clear to you.
Thanks
[ March 19, 2003: Message edited by: Vivek Saxena ]
 
Md Fizal
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it. Thanks Vivek...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic