File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes XSLT questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XSLT questions " Watch "XSLT questions " New topic
Author

XSLT questions

Mohit Sinha
Ranch Hand

Joined: Nov 29, 2004
Posts: 125
Hi All

Here are a few XSLT questions. I am in the process of converting an existing xml to a different xml



This is one sample XML adhering to the above DTD

*****************************************

<countries>
<country>
<country_name>India</country_name>

<node node_id="2" cid="111" oid="10">
<node_name>Maharashtra</node_name>


<node node_id="33" cid="222" oid="20">
<node_name>Mumbai</node_name>


<node node_id="7271" cid="333" oid="30">
<node_name>Dadar</node_name>
</node>

<country>
</countries>


In the xslt I want to iterate something like this & create a xml payload

when oid =10
<xml_torender> \India\Maharashtra </xml_torender>
when oid=20
<xml_torender> \India\Maharashtra\Mumbai </xml_torender>

when oid=30
<xml_torender> \India\Maharashtra\Mumbai\Dadar </xml_torender>


****************Here is what I am trying to write *********************

This is not the verified one just a rough idea

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xslutput omit-xml-declaration="yes" method="xml" encoding="UTF-8" indent="yes"/>

<xsl:param name="includeParent" select="'\India'" />


<xsl:template match="/*">

<xsl:if test="node/[@oid=10]">



<xsl:choose>
<xsl:when test="node_name != ''">
<myownxml>
<xmltorender channelType="subChannel">
<name>
<xsl:value-of select="$includeParent"/><xsl:value-of select="node_name"/>
</name>
</xmltorender>
</myownxml>
</xsl:when>
</xsl:choose>


</xsl:when>
</xsl:choose>

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




My main questions here is I have seen examples of <xsl:when> which access element values but not attributes. How do I
use an element's attribute in the when clause.

My second question is if you see \India is common. So I want to set the same as a global variable & keep on modifying
it as & when i go about transformation

My third & most important question is how do I distinguish between the inner node elements & the outer ones & take appropriate
action in XSLT. Since the outer node (oid=10) is similar to the inner nodes (oid =20 & oid =30) how can i write a rule in
xslt to distinguish the same



Regards
Nicolas Stern
Ranch Hand

Joined: Apr 26, 2002
Posts: 57
Hi

To access attributes use the @ xpath operator



HTH - Cheers
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XSLT questions
 
Similar Threads
override xml/xsd file by using .xsl and java
xsl - differentiating nodes
xhtml to xhtml using xslt
Newbie Question---Help?
retrieving ancestors