XSLT Node-set Parameter



I'm making a survey tool. Each respondent will be asked to answer questions on (for example) cakes. The number and types of cake will be different for each respondent. The format of the survey will be saved in a file called survey.xml. So the survey may be like the following:

Rates these cakes fool.
Birthday 0 1 2
Christmas 0 1 2
Lovely 0 1 2

Anyway, I want to pass these cakes into XSLT as a temporary XML document. E.g.:

<cakes> <cake>Birthday</cake> <cake>Christmas</cake> <cake>Lovely</cake></cakes>

I save that in a string and throw it in an XDocument like so:


Related to : XSLT Node-set Parameter
XML to HTML using XSLT without Hardcoding Node names in XSLT
ASP & ASP.net

Hi All,

I am new to XML,XSLT. I have been assigned to task of Generating HTML pages based on the XML file & the condition is No Hardcoding of Nodes and other details.

My XML file is of the below struct:

Node inside Nodes , and those nodes would contain any number of attribuites or elements.


Now i need to knw , is there any Generic XSLT Algorithm to can do the above job and render the HTML page in the form of Navigation Tabs?

Please advice...


XSLT Node-set Parameter
ASP & ASP.net

I'm making a survey tool. Each respondent will be asked to answer questions on (for example) cakes. The number and types of cake will be different for each respondent. The format of the survey will be saved in a file called survey.xml. So the survey may be like the following:

Rates these cakes fool.
Birthday 0 1 2
Christmas 0 1 2
Lovely 0 1 2

Anyway, I want to pass these cakes into XSLT as a temporary XML document. E.g.:

<cakes> <cake>Birthday</cake> <cake>Christmas</cake> <cake>Lovely</cake></cakes>

I save that in a string and throw it in an XDocument like so:

xslt node-set use in key function - find children by parent attribute
ASP & ASP.net

I have an XML File.

<?xml version="1.0" encoding="UTF-8"?>
<XML>   
    <Items>
        <ItemRef ID='answer'></ItemRef>
        <ItemRef ID='number'></ItemRef>
        <ItemRef ID='delete'></ItemRef>
        <ItemRef ID='remove'></ItemRef>
    </Items>
    <ItemDef ID='anwser'></ItemDef>
    <ItemDef ID='number'>
        <EnumItemRef EID = '1'></EnumItemRef>
    </ItemDef>
    <ItemDef ID='delete'>
        <EnumItemRef EID = '2'></EnumItemRef>
    </ItemDef>        
    <ItemDef ID='remove'></ItemDef>
    <EnumItem EID="1">
        <EnumItem Value = '1'></EnumItem>
        <EnumItem Value = '2'></EnumItem>
        <EnumItem Value = '3'></EnumItem>
    </EnumItem>
    <EnumItem EID="2">
        <EnumItem Value = 'yes'></EnumItem>
        <EnumItem Value = 'no'></EnumItem>
    </EnumItem>
</XML>

what I need to transform into a XML file like this:

<?xml version="1.0" encoding="UTF-8"?>
<XML>   
    <Items>
        <ItemRef ID='newid_answer'></ItemRef>
        <ItemRef ID='newid_number'></ItemRef>
    </Items>
    <ItemDef ID='newid_answer'></ItemDef>
    <ItemDef ID='newid_number'>
        <EnumItemRef EID = '1'></EnumItemRef>
    </ItemDef>        
    <EnumItem EID="1">
        <EnumItem Value = '1'></EnumItem>
        <EnumItem Value = '2'></EnumItem>
        <EnumItem Value = '3'></EnumItem>
    </EnumItem>
</XML>

I have following XSLT 1.0 file. With this I'm able to create the Items and ItemDefs I want. I'm just missing an idea how to find the corresonding EnumItemRef and EnumItem. Either I have to check if the current ItemDef has a child called EnumItemRef, or I could solve it with a key function (what would maybe be the better solution). I tried both but I can't make it work.

<xsl:variable name="Items">
    <Item ID="answer">newid_answer</Item>
    <Item ID="number">newid_number</Item>
</xsl:variable>

<xsl:key name="get_Enum_by_ID" match="/XML/ItemDef/EnumItemRef"
use="/XML/ItemDef/@ID" />

<xsl:template match="XML">
    <xsl:copy>
        <xsl:apply-templates />
        <xsl:call-template name="Items" />
        <xsl:call-template name="ItemDef" />
    </xsl:copy>
</xsl:template>

<xsl:template name="Items">
        <xsl:element name="Items">
        <xsl:for-each select="exslt:node-set($Items)/Item">
            <xsl:element name="ItemRef">
                <xsl:attribute name="ID"><xsl:value-of
select="text()"/></xsl:attribute>
            </xsl:element>
        </xsl:for-each>
    </xsl:element>
</xsl:template>

<xsl:template name="ItemDef">
    <xsl:for-each select="exslt:node-set($Items)/Item">
        <xsl:element name="ItemDef">
            <xsl:attribute name="ID"><xsl:value-of
select="text()" /></xsl:attribute>
        </xsl:element>
        <-- how can I find the corresponding EnumitemRef and
EnumItem? -->
        <xsl:copy-of select="key('get_Enum_by_ID', @ID)" /> 

    </xsl:for-each>
</xsl:template>

I would be happy if anyone could give me an idea how to solve this.


Xslt: How to change node text in element using a parameter
ASP & ASP.net

I need to change the text of certain nodes, similar to Update the text of an element with XSLT based on param.

This is my XML:

<entry>
    <form type="hyperlemma" xml:lang="cu">
         <orth>абиѥ</orth>
    </form>
    <form type="lemma" xml:lang="cu">
         <orth>абиѥ</orth>      
    </form>
    <form type="variant" xml:lang="cu">
         <orth>а̓бїе</orth>
         <form type="hyperlemma" xml:lang="cu">
             <orth>а̓бїе</orth>
         </form>
    </form>
</entry>

I now want to replace the text between <orth> in

<form type="variant" xml:lang="cu">
    <orth>а̓бїе</orth>
    <form type="hyperlemma" xml:lang="cu">
        <orth>а̓бїе</orth>
    </form>
</form>

by the content of <orth> in the previous node

<entry>
    <form type="hyperlemma" xml:lang="cu">
        <orth>абиѥ</orth>
    </form>

in order to get the following output:

<entry>
    <form type="hyperlemma" xml:lang="cu">
        <orth>абиѥ</orth>
    </form>
    <form type="lemma" xml:lang="cu">
        <orth>абиѥ</orth>      
    </form>
    <form type="variant" xml:lang="cu">
        <orth>а̓бїе</orth>
        <form type="hyperlemma" xml:lang="cu">
            <orth>абиѥ</orth>
        </form>
    </form>
 <entry>

When I use the following stylesheet

<?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"
xpath-default-namespace="http://www.tei-c.org/ns/1.0"
version="2.0">
<xsl:output method="xml" indent="yes" />
<xsl:strip-space elements="*" />

<xsl:param name="replace_orth"
select="entry/form[@type='hyperlemma' and @xml:lang='cu']/orth" />

<xsl:template match="node()|@*">
    <xsl:copy>
        <xsl:apply-templates select="node()|@*" />
    </xsl:copy>
</xsl:template>

<xsl:template match="form[@type='variant']/form[@type='hyperlemma'
and @xml:lang='cu']/orth/text()">
    <xsl:value-of select="$replace_orth" />
</xsl:template>
</xsl:stylesheet>

then I get

<form type="variant" xml:lang="cu">
    <orth>а̓бїе</orth>
    <form type="hyperlemma" xml:lang="cu">
         <orth/>
</form>

So <orth> is empty. If I change the parameter to

<xsl:param name="replace_orth" select="'new orth'" />

'new orth' gets printed. But as the content of <entry><form type="hyperlemma" xml:lang="cu"><orth> is different for each entry, I cannot use a 'static' string.

What do I need to change?

Thanks for any hint!


xslt filter variable node-set using input
ASP & ASP.net

I'm having trouble with, what I believe, is an inability to filter a variable node-set.

I have a variable which is populated with a node-set from a collection of documents and I'd like to echo the input and add the variable nodes if those nodes don't already exist in the input.

<xsl:variable name="views"
select="collection('file:/C:/temp/?select=*.xml;recurse=yes')"/>   


<xsl:template match="node()|@*">
    <xsl:copy>
        <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="/head">
    <xsl:copy>
        <xsl:apply-templates select="@* | *"/> 
<!-- having trouble with the filter here never works -->
        <xsl:for-each
select="$views/someElement[not(@name=(someInputElement/@name))]">-->
<!-- copy stuff in -->
        </xsl:for-each>
    </xsl:copy>
</xsl:template>

any advice most appreciated.


XSLT 1.0: dynamically set node value based on value set for previous node
ASP & ASP.net

I am trying to set a value for a node based on a value that may or may not have been set for a previous node in a list. I need to use XSLT 1.0 because this is being done within the IBM DataPower appliance. There is more to it than this, but I think this breaks it down to the bare essentials.

I am trying to identify number ranges that have no preceding number ranges with overlapping numbers. Once a number range has its IsUnique element set to true, all other overlapping number ranges following it MUST have their IsUnique element set to false.

If I have an XML doc that looks like this:

<Range>
    <Start>1</Start>
    <End>10</End>
    <IsUnique>true</IsUnique>
</Range>
<Range>
    <Start>11</Start>
    <End>20</End>
    <IsUnique>false</IsUnique>
</Range>
<Range>
    <Start>15</Start>
    <End>21</End>
    <IsUnique>false</IsUnique>
</Range>
<Range>
    <Start>25</Start>
    <End>30</End>
    <IsUnique>false</IsUnique>
</Range>

I want it to flip the IsUnique value on the second Range to "true" since its range does not overlap with any of the previous ranges. I do NOT want it to flip the third one since its range overlaps with the second one. I want it to flip the forth one to true since its range does not overlap with any of the previous ranges. I am not able to figure out how to "see" that a previous node's IsUnique value has been flipped when processing subsequent nodes. It sounds so simple and I suspect there is some simple solution I am missing, but I am not able to get it to work as desired. I assume I need to use an RTF and exsl:node-set(), but I have not found the right incantation to get it to work. Thanks!



Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © bighow.org All Rights Reserved .