Reputation: 1888
I have an xml
<?xml version="1.0"?>
<ArrayOfSubscriber xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Subscriber>
<FirstName xsi:nil="true" xmlns="somenamespace" />
<LastName xsi:nil="true" xmlns="somenamespace" />
...
</Subscriber>
...
</ArrayOfSubscriber>
I need to create an excel file where each column has its own style. I hoped to get what I expected using the next transformation
<Worksheet>
<Table>
<xsl:apply-templates select="//Subscriber" />
</Table>
</Worksheet>
<xsl:template match="Subscriber">
<Row ss:Height="15">
<Cell ss:StyleID="s21">
<Data ss:Type="String">
<xsl:value-of select="FirstName" />
</Data>
</Cell>
<Cell ss:StyleID="s22">
<Data ss:Type="String">
<xsl:value-of select="LastName " />
</Data>
</Cell>
...
</Row>
</xsl:template>
But the problem appears because of namespaces xmlns="somenamespace"
. Thus I can't get the data. I found a few topics where the possibility of removing them was described but as far as I new to xslt I didn't succeed in applying the right template to my task.
Upvotes: 0
Views: 367
Reputation: 2693
Try the alternative in the post I linked to earlier using a construct similar to this one:
<xsl:value-of select="*[local-name()='FirstName' = and namespace-uri()='somenamespace']" />
Previously suggested to define the namespace a parent element:
<parent xmlns:sn="somenamespace">
...
<xsl:template match="Subscriber">
<Row ss:Height="15">
<Cell ss:StyleID="s21">
<Data ss:Type="String">
<xsl:value-of select="sn:FirstName" />
</Data>
</Cell>
<Cell ss:StyleID="s22">
<Data ss:Type="String">
<xsl:value-of select="sn:LastName " />
</Data>
</Cell>
...
</Row>
</xsl:template>
...
</parent>
Upvotes: 1