Hwo to rewrite attribute to tags generically

M

moroder

Hi,

I'd like to rewrite this (some might recognize it as MarcXML)

....
<datafield tag="245" ind1="0" ind2="0">
<subfield code="a">Corpus Rubenianum Ludwig Burchard :</subfield>
<subfield code="b">an illustrated catalogue raisonné of the work of Peter
Paul Rubens.</subfield>
<subfield code="n">P.2,</subfield>
....
</datafield>
...

to this
....
<data245 ind1="0" ind2="0">
<suba>Corpus Rubenianum Ludwig Burchard :</suba>
<subb>an illustrated catalogue raisonné of the work of Peter Paul
Rubens.</subb>
...

Any tips? I've done things like this

<xsl:template match="@code"><xsl:element name="c{.}"><xsl:value-of
select="parent::node()"/></xsl:element></xsl:template>

but I get only halfway, and get duplicate values allover the place, and...
etc :-(

Thanks!

moro
 
D

David Carlisle

(don't use "tag" when you mean "element", XSLT can't process tags)

Something like

<xsl:template match="datafield">
<xsl:element name="data{@tag}">
<xsl:copy-of select="@*[not(name()='tag')]"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

<xsl:template match="subfield">
<xsl:element name="sub{@code}">
<xsl:copy-of select="@*[not(name()='code')]"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top