C Sharper
C Sharper

Reputation: 8626

c# How to get attribute name from xslt

I have following part of xslt in string format :-

<xsl:if test="TestValue3 and TestValue3 != ''">
                                                <xsl:attribute name = "TestDate" >
                                                <xsl:value-of select = "TestValue3" />
                                                </xsl:attribute>
                                                </xsl:if>

I just want to fetch its attribute name from c# code.

Attribuute Name= TestDate

How can I achieve this?

Upvotes: 0

Views: 137

Answers (2)

programses
programses

Reputation: 313

If I understand you correctly this should do the job, otherwise please add more context.

<xsl:if test="TestValue3 and TestValue3 != ''">
  <xsl:if test="not(@TestDate)">
    <xsl:attribute name = "TestDate" >
      <xsl:value-of select = "TestValue3" />
    </xsl:attribute>
  </xsl:if>
</xsl:if>

Upvotes: 1

user585968
user585968

Reputation:

Use your favourite XML API to load the XSLT and iterate/query the item in question (in this case you would need to look for the owning xsl:if and the condition itself). e.g. you could load it into an XmlDocument or XDocument.

You can use XPath to find the element for XmlDocuments or if you use XDocument you can use LINQ.

Do not attempt to use technologies that are not equipped for structured data.

i.e.

  • don't use flat string search
  • don't use regex

Actually I am adding above block into existing xslt ,, but before adding I need to check if attribute name =TestDate already exists ... For that I need to know attribute name , becase attribute name can vary as per block,, it is not fix each time

Again, use the above recommendations. Both XmlDocument and XDocument allow for load/edit/save.

Upvotes: 2

Related Questions