Click here to Skip to main content

XML / XSL

    RSS: RSS Feed

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page  Show 
  Refresh
AnswerRe: Searching for multiple types with XPath PinsupporterMark Nischalke8:06 10 Jul '10  
AnswerRe: Searching for multiple types with XPath Pinmembersameerazazi873:07 7 Aug '10  
QuestionXpath problem Pinmembersnehasish1:27 9 Jul '10  
AnswerRe: Xpath problem PinmvpStuart Dootson12:12 9 Jul '10  
QuestionExcel to XML conversion Pinmemberpriyaahh19:49 5 Jul '10  
AnswerRe: Excel to XML conversion Pinmemberevd4621:13 10 Aug '10  
Questionxsl:apply-templates help please! [modified] PinmemberNeophyte305:49 1 Jul '10  
I am attempting to digest someone elses xml - which is why I can't just reformat it as I'd like. I think that applying templates (possibly nested) is the way to go, but I'm buggered if I can see how to do it properly - the w3schools site covers the basics, but not what I'm after. Can anyone a) solve my problem or b) point me to somewhere I can find a more in-depth explanation?
 
I'd even settle for c) "XSLT does not work that way!"
 
Source XML:
<Beds>
<Single>
	<Base>1</Base>
	<BaseCode>BER</BaseCode>
	<Mattress>2</Mattress>
	<MattressCode>BER</MattressCode>
	<Headboard>3</Headboard>
	<HeadboardCode>BER</HeadboardCode>
</Single>
<Double>
	<Base>0</Base>
	<BaseCode></BaseCode>
	<Mattress>1</Mattress>
	<MattressCode>BER</MattressCode>
	<Headboard>2</Headboard>
	<HeadboardCode>TBD</HeadboardCode>
</Double>
<King>
	<Base></Base>
	<BaseCode></BaseCode>
	<Mattress></Mattress>
	<MattressCode></MattressCode>
	<Headboard></Headboard>
	<HeadboardCode></HeadboardCode>
</King>
<Sofa>
	<Foam>5</Foam>
	<FoamCode>BER</FoamCode>
	<Metal></Metal>
	<MetalCode></MetalCode>
</Sofa>
</Beds>
 
Desired Output XML:
<Row>
	<Description>SingleBase</Description>
	<Value>BER</Value>
	<Quantity>1</Quantity>
</Row>
<Row>
	<Description>SingleMattress</Description>
	<Value>BER</Value>
	<Quantity>2</Quantity>
</Row>
<Row>
	<Description>SingleHeadboard</Description>
	<Value>BER</Value>
	<Quantity>3</Quantity>
</Row>
<Row>
	<Description>DoubleMattress</Description>
	<Value>BER</Value>
	<Quantity>1</Quantity>
</Row>
<Row>
	<Description>DoubleHeadboard</Description>
	<Value>BER</Value>
	<Quantity>2</Quantity>
</Row>
<Row>
	<Description>SofaFoam</Description>
	<Value>BER</Value>
	<Quantity>5</Quantity>
</Row>
 
I thought I'd start with:
 
<xsl:for-each select="Beds">
          <Row>
            <xsl:apply-templates></xsl:apply-templates>
          </Row>
          
        </xsl:for-each>
 
but now I'm stuck as to how to access the nodename of the current node... Or whether to wrap in a choose (if that's even possible?)...

modified on Thursday, July 1, 2010 11:41 AM

AnswerRe: xsl:apply-templates help please! PinmemberNeophyte301:17 5 Jul '10  
GeneralRe: xsl:apply-templates help please! PinmvpStuart Dootson5:37 6 Jul '10  
AnswerRe: xsl:apply-templates help please! PinmvpStuart Dootson5:14 6 Jul '10  
GeneralRe: xsl:apply-templates help please! PinmemberNeophyte306:47 6 Jul '10  
GeneralRe: xsl:apply-templates help please! PinmvpStuart Dootson15:38 6 Jul '10  
QuestionHow to upload an Xml Schema to my ftp server and have Visual Studio provide intellisense for it? PinmemberTheodor Storm Kristensen3:07 1 Jul '10  
AnswerRe: How to upload an Xml Schema to my ftp server and have Visual Studio provide intellisense for it? PinsupporterMark Nischalke3:38 1 Jul '10  
GeneralRe: How to upload an Xml Schema to my ftp server and have Visual Studio provide intellisense for it? PinmemberTheodor Storm Kristensen4:11 1 Jul '10  
Questiontransformed cdata content not escaping properly (or atleast the way i want it it) Pinmembernyhtal20:59 30 Jun '10  
QuestionVXML Pinmembermuka665:15 29 Jun '10  
QuestionHow to create xmpp client using C#? Pinmembermanjeet pimpale0:13 18 Jun '10  
Answercross-post PinmvpLuc Pattyn3:27 18 Jun '10  
QuestionError in running ASP.NET C# (MySql) site PinmemberDot-Net-Dev18:24 16 Jun '10  
QuestionBeginner help to tag Bold text in DocBook v5 for XML export [modified] Pinmemberkeeta113:06 16 Jun '10  
QuestionWrite XSL for this xml i want to convert xml to CSV formt Pinmemberksanju100010:14 12 Jun '10  
AnswerRe: Write XSL for this xml i want to convert xml to CSV formt PinmemberSeMartens22:10 15 Jun '10  
Questionwriting to xml file PinmemberFarraj18:17 8 Jun '10  
AnswerRe: writing to xml file PinmvpStuart Dootson3:13 9 Jun '10  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web01 | 2.5.120209.1 | Last Updated 10 Feb 2012
Copyright © CodeProject, 1999-2012
All Rights Reserved. Terms of Use
Layout: fixed | fluid