PDA

View Full Version : XSLT Questions


Banana
2010-05-06, 20:24
I have two questions which I think my not knowing the right keyword is impending my googling so hopefully someone can bump me in the right direction:

1) I have a snippet of XML like this:

<badNameForArray>
<arrayChildElement>
...
</arrayChildElement>
...
</badNameForArray>

In this case, all child nodes are fine as they are and requires no transformation - I only need to transform the containing node. I don't see anything like rename, replace or something else that would allow me to import in a group of nodes without having to process them. I also tried xsl:apply-templates but it seems to just process the child nodes raw and not as unaltered XML?

2) I feel very dumb but somtimes the output results in this:

<aNode></aNode>

I don't want an empty element to show up at all. Does that mean I have to enclose the transformation in a if node?

Current XSLT code:

<aNode>
<xsl:value-of select="oldNode"/>
</aNode>

Does it have to be:
<xsl:if ...>
<aNode>
<xsl:value-of select="oldNode"/>
</aNode>
</xsl:if>
?

I tried xsi:nil but this doesn't seem to be what I am looking for?

Thanks! :)

Banana
2010-05-06, 23:39
Update:

Regarding the #2, it seems that there are two general solutions:

1) Build a template and use apply-template
2) Use a xsl:if and test for text().

I don't think #1 is the right solution because that would mean I'd be making 100s of templates for one nodes each - for a containing node, sure, but an individual node seems overkill. Thus I went with #2 but found it does not work too well when the data type is not text. Looking around, I found out that XML has a set of functions, mainly from XPath, so I figure I'd give them a try (empty and nilled in specific) but am having trouble importing them. I added a xmlns attribute to the XPath's URI but it doesn't seem to pick up the function definitions... Maybe I missed a step in importing the functions?