Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

xPath questions

 
Raymond Law
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would you give some advise of how to use xPath to convert attribute to element?
The original XML
<Doclists>
<Department name="IS">
<Cateogry name="MISC">
<Document>
<DocName>Mydocument</DocName>
<DocAuthor>Someone</ocAuthor>
</Document>
</Category>
</Department>
</Doclists>
I need to convert the above XML as follow:
<Doclists>
<Document>
<DocName>Mydocument</DocName>
<DocAuthor>Someone</ocAuthor>
<Departmen>IS</Department>
<Category>MISC</Category>
</Document>
</Doclists>
thanks your help in advance
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rlaw,
Welcome to Javaranch
We'd like you to read the Javaranch Naming Policy and change your publicly displayed name (change it here) to comply with our unique rule. Thank you.
PS: Quote from the naming policy:

For your publicly displayed name, use a first name, a space, and a last name. Obviously fictitious names or improperly formatted names may be locked out.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a modest start. It converts the contents of attribute name to be the department element data.

Cheers,
Dan
 
Raymond Law
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But how to retreive parent attribute when parsing child element like following?
The following doesn't work?
<xsl:template match="Document">
<Department>
<xsl:value-of select="parent::attribute::name"/>
</Department>
</xsl:template>
</xsl:stylesheet>

I really appreicate your help!!
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please try -

Cheers,
Dan
 
Raymond Law
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dan,
My problem finally got solved. I thought that I need to use "preceding-sibling" to get parent attribute, but "../../" can easily solve my problem. I need to spend more time on xPath.
Anyway, I really appreicate your help!

Thanks you!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic