Insert/Update text in a tag using xsl
Post here questions and problems related to oXygen frameworks/document types.
-
- Posts: 12
- Joined: Mon Dec 16, 2019 6:51 pm
Insert/Update text in a tag using xsl
Hi,
I have an empty tag (not a combobox)
I want to update the text inside of this tag depending on the value of a combobox publisher code
configuration xml file:
xsl file:
So if $linkedCode is BELANGER, I want this :
How would I do that?
Thanks
I have an empty tag (not a combobox)
Code: Select all
<publishername></publishername>
configuration xml file:
Code: Select all
<match elementName="publishername" editable="true">
<xslt href="getMetaCaijValues.xsl" useCache="false" action="replace"/>
</match>
Code: Select all
<xsl:template match="/">
<xsl:variable name="propertyElement"
select="saxon:eval(saxon:expression($contextElementXPathExpression, ./*))"/>
<xsl:choose>
<xsl:when test="$propertyElement/name() = 'publishername'">
<xsl:call-template name="getPublisherName"/>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="getPublisherName">
<xsl:variable name="linkedCode"
select="saxon:eval(saxon:expression(concat($contextElementXPathExpression,'/../meta.caij/md.publisher.code'), ./*))"/>
<xsl:if test="upper-case($linkedCode) = 'BELANGER'">
Bélanger Sauvé
</xsl:if>
</xsl:template>
Code: Select all
<publishername>Bélanger Sauvé</publishername>
Thanks
-
- Posts: 1016
- Joined: Wed Nov 16, 2005 11:11 am
Re: Insert/Update text in a tag using xsl
Post by alex_jitianu »
Hi,
It looks like you are pretty close to your goal. Here's an XSLT variant that I've tested on an XML instance like the one below. Let me know if there is anything missing. Please note that you can use xsl:message to add logging information that can help you understand why things don't go as planned.
It looks like you are pretty close to your goal. Here's an XSLT variant that I've tested on an XML instance like the one below. Let me know if there is anything missing. Please note that you can use xsl:message to add logging information that can help you understand why things don't go as planned.
Code: Select all
<test_cc>
<meta.caij>
<md.publisher.code>BELANGER</md.publisher.code>
</meta.caij>
<publishername></publishername>
</test_cc>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
xmlns:saxon="http://saxon.sf.net/"
version="2.0">
<xsl:param name="documentSystemID" as="xs:string"></xsl:param>
<xsl:param name="contextElementXPathExpression" as="xs:string"></xsl:param>
<xsl:template name="start">
<xsl:apply-templates select="doc($documentSystemID)"/>
</xsl:template>
<xsl:template match="/">
<xsl:variable name="propertyElement"
select="saxon:eval(saxon:expression($contextElementXPathExpression, ./*))"/>
<!--<xsl:message select="local-name($propertyElement)"></xsl:message>-->
<xsl:apply-templates select="$propertyElement"/>
</xsl:template>
<xsl:template match="publishername">
<!-- CC was invoked on element publishername -->
<xsl:variable name="linkedCode" select="../meta.caij/md.publisher.code"/>
<xsl:if test="upper-case($linkedCode) = 'BELANGER'">
<items action="replace">
<item value="Bélanger Sauvé"/>
</items>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
-
- Posts: 12
- Joined: Mon Dec 16, 2019 6:51 pm
Re: Insert/Update text in a tag using xsl
It didn't work.
Here's the xslt:
The other elements are comboboxes. I have a configuration file for those elements but it doesn't work with work with publishername since it is just a display:inline.
In the xslt, it doesn't go even once in the if.
Here's the xslt:
Code: Select all
<xsl:template match="/">
<xsl:variable name="propertyElement"
select="saxon:eval(saxon:expression($contextElementXPathExpression, ./*))"/>
<xsl:choose>
<xsl:when test="$propertyElement/name() = 'md.type'">
<xsl:call-template name="getTypeValues"/>
</xsl:when>
<xsl:when test="$propertyElement/name() = 'md.host.id'">
<xsl:call-template name="getHostIdValues"/>
</xsl:when>
<xsl:when test="$propertyElement/name() = 'md.host.title'">
<xsl:call-template name="getHostTitleValues"/>
</xsl:when>
<xsl:when test="$propertyElement/name() = 'md.publisher.code'">
<xsl:call-template name="getPublisherCodeValues"/>
</xsl:when>
<xsl:when test="$propertyElement/name() = 'md.primary'">
<xsl:call-template name="getPrimaryValues"/>
</xsl:when>
<xsl:when test="$propertyElement/name() = 'md.secondary'">
<xsl:call-template name="getSecondaryValues"/>
</xsl:when>
</xsl:choose>
<xsl:if test="$propertyElement/name() = 'publishername'">
<xsl:message>Out</xsl:message>
</xsl:if>
</xsl:template>
Code: Select all
<match elementName="md.type" editable="onlyAllowedItems">
<xslt href="getMetaCaijValues.xsl" useCache="false" action="replace"/>
</match>
<match elementName="md.host.id" editable="onlyAllowedItems">
<xslt href="getMetaCaijValues.xsl" useCache="false" action="replace"/>
</match>
<match elementName="md.host.title" editable="onlyAllowedItems">
<xslt href="getMetaCaijValues.xsl" useCache="false" action="replace"/>
</match>
<match elementName="md.publisher.code" editable="onlyAllowedItems">
<xslt href="getMetaCaijValues.xsl" useCache="false" action="replace"/>
</match>
<match elementName="md.primary" editable="onlyAllowedItems">
<xslt href="getMetaCaijValues.xsl" useCache="false" action="replace"/>
</match>
<match elementName="md.secondary" editable="onlyAllowedItems">
<xslt href="getMetaCaijValues.xsl" useCache="false" action="replace"/>
</match>
<match elementName="publishername" editable="true">
<xslt href="getMetaCaijValues.xsl" useCache="false" action="replace"/>
</match>
-
- Posts: 1016
- Joined: Wed Nov 16, 2005 11:11 am
Re: Insert/Update text in a tag using xsl
Post by alex_jitianu »
Hi,
In the XSLT, do you also have a template named "start"? it is the entry point.
Can you send me the XSLT, cc_config.xml and an XML instance on support@oxygenxml.com ? This way I can put them together and understand what's happening. Afterwards, I will remove them from my system.
Best regards,
Alex
In the XSLT, do you also have a template named "start"? it is the entry point.
So for the other elements, which use combo boxes form controls, the proposed values are presented correctly? The CSS doesn't really matter... The configuration file works at a low level, in every place where proposals are needed, those values are contributed. For example, even if you go into the text page, if you place the caret inside the element and press CTRL + Space, the values are presented.The other elements are comboboxes. I have a configuration file for those elements but it doesn't work with work with publishername since it is just a display:inline.
Can you send me the XSLT, cc_config.xml and an XML instance on support@oxygenxml.com ? This way I can put them together and understand what's happening. Afterwards, I will remove them from my system.
Best regards,
Alex
Return to “SDK-API, Frameworks - Document Types”
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