What is the XSLT to write certain node attributes one-to-a-line?

Posted by Scott Stafford on Stack Overflow See other posts from Stack Overflow or by Scott Stafford
Published on 2010-04-19T14:49:40Z Indexed on 2010/04/19 15:23 UTC
Read the original article Hit count: 209

Filed under:
|
|

I want an XML stylesheet (XSLT) that will put the attributes of a few, specific, child nodes one-to-a-line. What is the XSLT for this?

I recently asked a related question that someone offered a stylesheet to solve but their stylesheet didn't work for some reason, and I am curious why -- the attributes simply didn't end up one-per-line.

By way of example, my XML might look like this:

<MyXML>
    <NodeA>
       <ChildNode value1='5' value2='6' />
    </NodeA>
    <NodeB>
       <AnotherChildNode value1='5' value2='6' />
    </NodeB>
    <NodeC>
       <AnotherChildNode value1='5' value2='6' />
    </NodeC>
</MyXML>

And I want a stylesheet that will expand all NodeA's and NodeB's but not NodeCs and make it look like this:

<MyXML>
    <NodeA>
       <ChildNode 
          value1='5' 
          value2='6' />
    </NodeA>
    <NodeB>
       <AnotherChildNode 
          value1='5' 
          value2='6' />
    </NodeB>
    <NodeC>
       <AnotherChildNode value1='5' value2='6' />
    </NodeC>
</MyXML>

© Stack Overflow or respective owner

Related posts about xslt

Related posts about Xml