Find and Copy into another element?
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 8
- Joined: Thu May 15, 2014 10:06 pm
Find and Copy into another element?
Is there a way to copy data from one element and paste the data into another element?
For example, how can the image in <page1> be copied into <page2> programmatically?
Thanks!
For example, how can the image in <page1> be copied into <page2> programmatically?
Code: Select all
<object>
<page1>
<image>pathtoimage/image-to-copy.png</image>
</page1>
<page2>
<image></image>
</page2>
<pag
</object>
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Find and Copy into another element?
Hi,
Are you looking for an XSLT or XQuery solution that does this, or a programming language in particular?
What tools do you have at hand? Do you want to do this within Oxygen or do you want to automate this independently from it?
Regards,
Adrian
Are you looking for an XSLT or XQuery solution that does this, or a programming language in particular?
What tools do you have at hand? Do you want to do this within Oxygen or do you want to automate this independently from it?
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Find and Copy into another element?
Hi,
You can use an XSL script that copies the content from the XML source and adjusts what you need in the output.
e.g. XSL that for the image in page2 copies the image path from the preceding page1/image (XSL is based on 'samples/xhtml/copy.xsl')
Save this in an .xsl file. To apply this in Oxygen you need to configure and run a transformation scenario.
Open the XML file and from the main menu invoke Document -> Transformation -> "Configure Transformation Scenario(s)" (there's a corresponding button in the toolbar)
In the Configure Transformation Scenario(s) dialog press New and select XML transformation with XSLT to create a new scenario:
1. Give it an appropriate name
2. Leave the XML URL field to its default(${currentFileURL})
3. In the XSL URL field browse for the stylesheet.
4. This is a '1.0' stylesheet, so you can leave the Transformer set to Saxon6.5.5.
5. You can further tune the Output. Please note that the Save as field must refer a single file, NOT an output directory. Use the editor variables to compose a generic name instead of a fixed one.
e.g in the "Save as" field you can specify: ${cfd}/${cfn}-out.xml which translates into <current-file-directory>/<current-filename>-out.xml
6. Press OK in the editing dialog and "Apply associated" to run it.
Regards,
Adrian
You can use an XSL script that copies the content from the XML source and adjusts what you need in the output.
e.g. XSL that for the image in page2 copies the image path from the preceding page1/image (XSL is based on 'samples/xhtml/copy.xsl')
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<!-- Match document -->
<xsl:template match="/">
<xsl:apply-templates mode="copy" select="."/>
</xsl:template>
<!-- Deep copy template -->
<xsl:template match="*|text()|@*" mode="copy">
<xsl:copy>
<xsl:apply-templates mode="copy" select="@*"/>
<xsl:apply-templates mode="copy"/>
</xsl:copy>
</xsl:template>
<xsl:template match="image" mode="copy">
<xsl:copy>
<xsl:apply-templates mode="copy" select="@*"/>
<xsl:if test="parent::page2">
<xsl:apply-templates mode="copy"
select="parent::page2/preceding-sibling::page1[1]/image/text()"/>
</xsl:if>
<xsl:if test="not(parent::page2)">
<xsl:apply-templates mode="copy"/>
</xsl:if>
</xsl:copy>
</xsl:template>
<!-- Handle default matching -->
<xsl:template match="*"/>
</xsl:stylesheet>
Open the XML file and from the main menu invoke Document -> Transformation -> "Configure Transformation Scenario(s)" (there's a corresponding button in the toolbar)
In the Configure Transformation Scenario(s) dialog press New and select XML transformation with XSLT to create a new scenario:
1. Give it an appropriate name
2. Leave the XML URL field to its default(${currentFileURL})
3. In the XSL URL field browse for the stylesheet.
4. This is a '1.0' stylesheet, so you can leave the Transformer set to Saxon6.5.5.
5. You can further tune the Output. Please note that the Save as field must refer a single file, NOT an output directory. Use the editor variables to compose a generic name instead of a fixed one.
e.g in the "Save as" field you can specify: ${cfd}/${cfn}-out.xml which translates into <current-file-directory>/<current-filename>-out.xml
6. Press OK in the editing dialog and "Apply associated" to run it.
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
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