• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

xPath questions

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please try -

Cheers,
Dan
 
Raymond Law
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic