File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XSLT questions " Watch "XSLT questions " New topic

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



<node node_id="2" cid="111" oid="10">

<node node_id="33" cid="222" oid="20">

<node node_id="7271" cid="333" oid="30">


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"
<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:when test="node_name != ''">
<xmltorender channelType="subChannel">
<xsl:value-of select="$includeParent"/><xsl:value-of select="node_name"/>



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

Nicolas Stern
Ranch Hand

Joined: Apr 26, 2002
Posts: 57

To access attributes use the @ xpath operator

HTH - Cheers
I agree. Here's the link:
subject: XSLT questions
It's not a secret anymore!