Adress text of child code
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 4
- Joined: Thu Aug 09, 2018 3:29 pm
Adress text of child code
Hi,
I apply following template and want foo get filled with "bar1" or "bar2". How can I select the value of abc:foo?
Thanks for your help!
I apply following template and want foo get filled with "bar1" or "bar2". How can I select the value of abc:foo?
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:abc="http://example.net/V3.0/ABCSchema" exclude-result-prefixes="abc">
<xsl:template match="/">
<xsl:apply-templates select="//abc:test/abc:vertreter"/>
</xsl:template>
<xsl:template match="//abc:test/abc:vertreter">
<Vertreter>
<xsl:attribute name="foo"><xsl:value-of select="node()/foo/text()"/></xsl:attribute>
<xsl:attribute name="ID"><xsl:value-of select="position()"/></xsl:attribute>
</Vertreter>
</xsl:template>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<abc:test xmlns:abc="http://example.net/V3.0/ABCSchema">
<abc:vertreter>
<abc:foo>bar1</abc:foo>
</abc:vertreter>
<abc:vertreter>
<abc:foo>bar2</abc:foo>
</abc:vertreter>
</abc:test>
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Adress text of child code
Hi,
Maybe replace:
with:
Explanation:
1) The "node()" path means any child of the current element. As the current element is "vertreter", an expression like "node()/foo" would mean search for a grandchild called "foo" but "foo" is a child of "vertreter".
2) As all the elements in the XML are namespaced, you need to use the "abc:" prefix whenever referencing element names from the XML in the XPath.
3) Two expressions like this:
and:
are equivalent because "xsl:value-of" basically means "get the text content of".
Regards,
Radu
Maybe replace:
Code: Select all
<xsl:value-of select="node()/foo/text()"/>
Code: Select all
<xsl:value-of select="abc:foo"/>
1) The "node()" path means any child of the current element. As the current element is "vertreter", an expression like "node()/foo" would mean search for a grandchild called "foo" but "foo" is a child of "vertreter".
2) As all the elements in the XML are namespaced, you need to use the "abc:" prefix whenever referencing element names from the XML in the XPath.
3) Two expressions like this:
Code: Select all
<xsl:value-of select="abc:foo"/>
Code: Select all
<xsl:value-of select="abc:foo/text()"/>
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
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