Domanda

I have a value coming from SharePoint as <xsl:value-of select="@fldNm" />

This will have 1 of 2 possible values: an empty string, or 'yes.' This is within <xsl:template name="dvt_1.rowedit"> of a SharePoint display form.

If the value is an empty string, I want to dislpay one character, but if it is 'yes' I want to display a different character.

I am putting a tag inline with the HTML, and using document.write(). But I am having no luck making the actions respond to the value of fldNm.

I have found a lot of examples, but they are so different than what I am trying to do that I can't make sense of them.

This is the situation:

When you create a SharePoint Custom List, 3 .aspx pages are created for you: newForm, editForm and dispForm.

These .aspx pages are loaded with all kinds of xsl and xslt functionality. Several xsl templates are created, one of which holds the HTML that will show when the .aspx is used. That template is named by SharePoint as 'dvt_1.' That template is then called in a <xsl:for-each select="$Rows"> xsl structure.

Within that called template on the dispForm page, each datum is shown through the use of

    <td>
       <div>
            <xsl:value-of select="@fieldName" />
       </div>
    </td>

When the page is rendered, that 'value-of' tag is replaced with the contents of whatever field was psecified (of course).

In my case, because of the Design Requirements document, the field I am asking about will contain 'yes' or ''.

If it is yes, I want to use a put a single character there indicating the 'yes.' Otherwise I want to put a different character there, indicating 'not yes.'

I cannot figure out how to get the rendered value into a choice-making construct.

I tried something like

    <td>
    The answer is: <script> if (<xsl:value-of select="@fieldName" /> == 'yes') {
    document.write('A');
    } else {
    document.write('B');
    }
    </script>
    </td>

but the xsl tag was not recognized as such.

I am very new to xsl, and though I am starting to see how the syntax accomplishes things, it is still very mysterious to me.

È stato utile?

Soluzione

Since you haven't provided us much info, this is the best answer I can give.

As shown in this answer:

A more general XPath 1.0 expression that produces the string $s1 if $val is "x" and produces the string $s2 if $val is "y" :

concat(substring($s1, 1 div ($val = "x")),
       substring($s2, 1 div ($val = "y"))
      )

If I understand your question correctly, this principle can be used to generate the expected answer. To see this, look at the following sample:

Assumptions:

  • A value of "yes" should output the character "a"
  • A value of "" should output the character "b"

When this XSLT (which uses the aforementioned XPath):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output omit-xml-declaration="yes" indent="yes" method="text"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="e">
    <xsl:text>The value is: </xsl:text>
    <xsl:value-of
      select="concat(substring('a', 1 div (@fldNm = 'yes')), 
                     substring('b', 1 div (@fldNm = ''))
              )"/>
    <xsl:text/>
  </xsl:template>

</xsl:stylesheet>

...is applied to the following sample XML:

<t>
  <e fldNm="yes"/>
  <e fldNm=""/>
</t>

...the wanted result is produced:

The value is: a
The value is: b

Altri suggerimenti

Use:

substring('yx', 1 + (@fldNm = 'yes'), 1)

The evaluation of this expression produces the character "x" if the value of the attribute (of the context node) named "fldNm" is "yes", otherwise the evaluation produces the character "y".

Here we use the fact that by definition:

 number(true()) = 1

and

 number(false()) = 0 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top