Can the same stylesheet manipulate the results of "Copy-of"?
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 6
- Joined: Fri Jan 23, 2009 8:20 pm
Can the same stylesheet manipulate the results of "Copy-of"?
I'm a very elementary user of XSL (Oxygen is a great tool), and I don't need to do many complicated things, but this has me stumped. I have an XML corpus of language texts following TEI norms. I am developing an XSL stylesheet that manipulates the data and converts the files to HTML. I need to transfer entire paragraphs of text direct from XML to HTML. However, I also need to manipulate some of the XML elements within these paragraphs, for example the tagged verb forms. How is this possible?
If I use "copy-of" I get the paragraphs in my output with all the tags intact, but I can't seem to modify these tags within the paragraphs. To be specific, if my XML paragraph includes the following:
<w type="verb" lemma="confessar" ana="pt3">confesset
I want the output to be
<a class="v" href="#">confesset <span>confessar; pt3</span></a>
I can get this output in the HTML, but not inline within the paragraph. It shows up as an additional line, either before or after the paragraph, depending on how I organize the stylesheet.
I'd appreciate any ideas!
If I use "copy-of" I get the paragraphs in my output with all the tags intact, but I can't seem to modify these tags within the paragraphs. To be specific, if my XML paragraph includes the following:
<w type="verb" lemma="confessar" ana="pt3">confesset
I want the output to be
<a class="v" href="#">confesset <span>confessar; pt3</span></a>
I can get this output in the HTML, but not inline within the paragraph. It shows up as an additional line, either before or after the paragraph, depending on how I organize the stylesheet.
I'd appreciate any ideas!
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Re: Can the same stylesheet manipulate the results of "Copy-of"?
Assuming
as input then the following stylesheet
gives
Best Regards,
George
Code: Select all
<w type="verb" lemma="confessar" ana="pt3">confesset </w>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="w">
<a class="{substring(@type, 1, 1)}" href="#">
<xsl:value-of select="."/>
<span>
<xsl:value-of select="@lemma"/>
<xsl:text>; </xsl:text>
<xsl:value-of select="@ana"/>
</span>
</a>
</xsl:template>
</xsl:stylesheet>
Code: Select all
<a class="v" href="#">confesset <span>confessar; pt3</span></a>
George
George Cristian Bina
-
- Posts: 6
- Joined: Fri Jan 23, 2009 8:20 pm
Re: Can the same stylesheet manipulate the results of "Copy-of"?
Thanks for the unbelievably quick response. This gives me the fragment of html that I want, but I'm still not clear about how to get this output inline inside the paragraph that I'm transferring from the XML, rather than on a separate line afterwards. In other words, I have the following in XML
<p>Sans deu Miralh, de La Reula, <w lemma="reconeisser" ana="pt3">reconogo</w> et <lb/> <w lemma="confessar" ana="pt3"> confesset</w>, per sin, en nom et en loc de la dona na Miramonda, sa molher, <lb/> et molher qui <w lemma="esser" ana="pt3">fo</w>...</p>
And what I would like as output is
<p>Sans deu Miralh, de La Reula <a class="v" href="#">reconogo <span>reconeisser; pt3</span></a> et <br/> <a class="v" href="#">confesset <span>confessar; pt3</span></a>, per sin, en nom et en loc de la dona na Miramonda, sa molher, <br/> et molher qui <a class="v" href="#">fo <span>esser; pt3</span></a>...</p>
How do I get the entire text with these transformations within it? I tried using "copy-of" on the <body> element, but I don't seem to be able to do anything else with the results.
<p>Sans deu Miralh, de La Reula, <w lemma="reconeisser" ana="pt3">reconogo</w> et <lb/> <w lemma="confessar" ana="pt3"> confesset</w>, per sin, en nom et en loc de la dona na Miramonda, sa molher, <lb/> et molher qui <w lemma="esser" ana="pt3">fo</w>...</p>
And what I would like as output is
<p>Sans deu Miralh, de La Reula <a class="v" href="#">reconogo <span>reconeisser; pt3</span></a> et <br/> <a class="v" href="#">confesset <span>confessar; pt3</span></a>, per sin, en nom et en loc de la dona na Miramonda, sa molher, <br/> et molher qui <a class="v" href="#">fo <span>esser; pt3</span></a>...</p>
How do I get the entire text with these transformations within it? I tried using "copy-of" on the <body> element, but I don't seem to be able to do anything else with the results.
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Re: Can the same stylesheet manipulate the results of "Copy-of"?
See the comments in the code
Regards,
George
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="p">
<!-- Copy the p element to the output -->
<xsl:copy>
<!-- copy eventual attributes of p -->
<xsl:copy-of select="@*"/>
<!-- apply the stylesheet templates on p content -->
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="w">
<a href="#">
<xsl:attribute name="class">
<!-- If we have a type attribute use its first letter, otherwise output v -->
<xsl:choose>
<xsl:when test="@type">
<xsl:value-of select="substring(@type, 1, 1)"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>v</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="."/>
<span>
<xsl:value-of select="@lemma"/>
<xsl:text>; </xsl:text>
<xsl:value-of select="@ana"/>
</span>
</a>
</xsl:template>
<xsl:template match="lb">
<br/>
</xsl:template>
</xsl:stylesheet>
George
George Cristian Bina
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service