ALMOST WORKING was Re: [xsl] XSLT to populate a SAML AttributeStatement from an XML

Subject: ALMOST WORKING was Re: [xsl] XSLT to populate a SAML AttributeStatement from an XML
From: "ohaya ohaya@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 19 Jan 2023 13:05:13 -0000
 I tried the XSLT on the gateway, which does have XSLT 2.0. It looks like it
worked, but it's generating some "EXTRANEOUS" output... specifically,
it looks like is outputting the VALUE of some the other elements, I am not
sure why :(...

1-Here's the source XML:

<record>
 <adrRecord>
 <PN_ID>1111111</PN_ID>
 <personnel>
 <ADM_ORG_CD>urn:NORM:DEPT</ADM_ORG_CD>
 <DOD_ASSOC_CD>urn:NORM:V01</DOD_ASSOC_CD>
 </personnel>
 </adrRecord>
</record>




2-Here's the XSLT:

<xsl:stylesheet version="1.0"
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>


<xsl:template match="/">
 <saml:AttributeStatement>
 <xsl:apply-templates select="/record/adrRecord/*"/>
 </saml:AttributeStatement>
</xsl:template>

<xsl:template match="/record/adrRecord/personnel/ADM_ORG_CD">
<saml:Attribute Name="MY_ORG_CD"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">

 <xsl:for-each select="tokenize(.,':')">
 <saml:AttributeValue xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xsi:type="xsd:string"><xsl:value-of select="."/></saml:AttributeValue>
 </xsl:for-each>
</saml:Attribute>
</xsl:template>


<!--
<xsl:template match="/record/adrRecord/personnel/ADM_ORG_CD">
<saml:Attribute Name="MY_ORG_CD"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
 <saml:AttributeValue xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xsi:type="xsd:string"> <xsl:value-of
select="/record/adrRecord/personnel/ADM_ORG_CD" />
</saml:AttributeValue>
</saml:Attribute>
</xsl:template>

<xsl:template match="/record/adrRecord/personnel/DOD_ASSOC_CD">
<saml:Attribute Name="MY_ASSOC_CD"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
 <saml:AttributeValue xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xsi:type="xsd:string"> <xsl:value-of
select="/record/adrRecord/personnel/DOD_ASSOC_CD" />
</saml:AttributeValue>
</saml:Attribute>

</xsl:template>
-->

</xsl:stylesheet>



3-Here's the output when I run the XSLT:

<?xml version="1.0" encoding="UTF-8"?><saml:AttributeStatement
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>1111111<saml:Attribute
Name="MY_PN_ID"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"><saml:Attribut
eValue xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xsi:type="xsd:string">urn</saml:AttributeValue><saml:AttributeValue
xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xsi:type="xsd:string">NORM</saml:AttributeValue><saml:AttributeValue
xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xsi:type="xsd:string">DEPT</saml:AttributeValue></saml:Attribute>urn:NORM:V01
</saml:AttributeStatement>



NOTICE that it is outputting the "
1111111" and the "urn:NORM:V01".

Why is that?

Thanks!

Jim

     On Thursday, January 19, 2023, 02:58:16 AM EST, ohaya ohaya@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

  BTW, I mentioned I am using xsltproc to do initial testing. Is there a way
that I can tell if it support XSLT 2.0?




     On Thursday, January 19, 2023, 02:40:48 AM EST, ohaya <ohaya@xxxxxxxxx>
wrote:

  Hi Martin,

Actually I think that even without the difference in the name, I am going to
have to do one template match per attribute.

I didn't post the entire XSLT, but the reason that I am saying that is that in
the XML that is the source, not all have the same path (e.g. there is
personnel, enterprise).

So given that, can you (or someone) post a single template match including the
tokenize()?

Thanks,
Jim


     On Thursday, January 19, 2023, 01:50:01 AM EST, Martin Honnen
martin.honnen@xxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:




 Am 1/19/2023 um 4:58 AM schrieb ohaya ohaya@xxxxxxxxx:


 Hi All,

 Thanks for the help thus far... I was able to integrate the code I posted
earlier today to construct a saml:AttributeStatement, and I was able to
integrate that with the rest of what I'm doing (there were a lot more
attributes, etc.

 So now, I think what I have left is to handle the multi-values.

 I think that Michael posted this (this also has his correction):

 <xsl:template match="personnel/*">
 <saml:Attribute Name="{name()}"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
 <xsl:for-each select="tokenize('.',':'.)">
 <saml:AttributeValue xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xsi:type="xsd:string"><xsl:value-of select="."/></saml:AttributeValue>

 but I am confused.

 In the code I had posted (for 3 of the attribs), I had one <xsl:template
match"> for each of the attribs.

 With the code above, are you all sayiI don't have to do that and just have a
single <xsl:template match>?



If there were a one to one relation between input data values and result names
you could use a single template, it seems however that we didn't notice that
e.g.


B 

 <PN_ID>1111111</PN_ID>is supposed to become saml:Attribute Name="MY_PN_ID"
while e.g.   <ADM_ORG_CD>urn:NORM:DEPT</ADM_ORG_CD>is supposed to become e.g.
saml:Attribute Name="MY_ORG_CD"and not    saml:Attribute
Name="MY_ADM_ORG_CD"Thus if you have to use a different approach for each name
you might need more templates than a single one that simply does e.g.
<saml:Attribute Name="MY_{name()}">As for the values, the suggested tokenize
approach, as far as I see it currently, would work, if there is no colon it
creates a single samlAttributeValue, if there are colons it creates several.

     On Wednesday, January 18, 2023, 04:08:40 PM EST, ohaya <ohaya@xxxxxxxxx>
wrote:

      Hi,

 I originally thought that also but didn't know how to add the root to the
XSLT (I tried just putting into the XSLT but it said that template had to be
top-level).

 Anyway, so I was also guessing the problem was what you said, so I found a
page the mentioned how to add the root and got this XSLT:

 <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
 xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
 >


 <xsl:template match="/">
 <saml:AttributeStatement>
 <xsl:apply-templates select="/record/adrRecord/*"/>
 </saml:AttributeStatement>
 </xsl:template>

 <xsl:template match="/record/adrRecord/PN_ID">
 <saml:Attribute Name="MY_PN_ID"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
 <saml:AttributeValue xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xsi:type="xsd:string"><xsl:value-of select="/record/adrRecord/PN_ID" />
 </saml:AttributeValue>
 </saml:Attribute>
 </xsl:template>

 <xsl:template match="/record/adrRecord/personnel/ADM_ORG_CD">
 <saml:Attribute Name="MY_ORG_CD"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
 <saml:AttributeValue xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xsi:type="xsd:string"> <xsl:value-of
select="/record/adrRecord/personnel/ADM_ORG_CD" />
 </saml:AttributeValue>
 </saml:Attribute>
 </xsl:template>

 <xsl:template match="/record/adrRecord/personnel/DOD_ASSOC_CD">
 <saml:Attribute Name="MY_ASSOC_CD"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
 <saml:AttributeValue xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xsi:type="xsd:string"> <xsl:value-of
select="/record/adrRecord/personnel/DOD_ASSOC_CD" />
 </saml:AttributeValue>
 </saml:Attribute>

 </xsl:template>


 </xsl:stylesheet>


 I






 XSL-List info and archiveEasyUnsubscribe(by email)    XSL-List info and
archiveEasyUnsubscribe(by email)

Current Thread